-2

This is basic but I have no idea how to do this.

There is an addEventListener that fires on page load.

var imgcnvs = document.createElement('canvas');
var imagecxt = imgcnvs.getContext('2d');

window.addEventListener('load', function(){
    //do something
}, false);

How can I convert window.addEventListener('load', function(){ to work when $('#startBtn') is clicked? `

Bekki
  • 719
  • 2
  • 12
  • 20

2 Answers2

3
$( "#startBtn" ).click(function() {
    //dosomething
 });

Please read the jquery documentation.

Sven van den Boogaart
  • 11,833
  • 21
  • 86
  • 169
2

You need to get your target element, using document.getElementById for instance, and then attach the event listener to it. As follows:

document.getElementById("startBtn").addEventListener("click", function(event) {
  // Do something
}, false);
Gustavo Straube
  • 3,744
  • 6
  • 39
  • 62