surajthemighty
surajthemighty

Reputation: 53

Change from jQuery to Plain Javascript

I am trying to replace all the jQuery dependency in the $(document).ready() function.

document.addEventListener('DOMContentLoaded', function() {
  $("#canvas1").mousedown(handleMouseDown);
  $(document).keydown(handleKeyDown);
}, false);

If handleKeyDown and handleMouseDown are previously declared functions in the same file function handleMouseDown() and function handleKeyDown(), how do I replace the jQuery with native javascript?

Upvotes: 0

Views: 67

Answers (1)

Dan D
Dan D

Reputation: 2523

Have you tried:

document.addEventListener('DOMContentLoaded', function(){

    document.getElementById('canvas1').onmousedown = handleMouseDown;

    document.onkeydown = handleKeyDown;

}, false);

Upvotes: 4

Related Questions