JavaScript: remove event listener

You need to use named functions. Also, the click variable needs to be outside the handler to increment. var click_count = 0; function myClick(event) { click_count++; if(click_count == 50) { // to remove canvas.removeEventListener(‘click’, myClick); } } // to add canvas.addEventListener(‘click’, myClick); EDIT: You could close around the click_counter variable like this: var myClick = … Read more

event.preventDefault() vs. return false

return false from within a jQuery event handler is effectively the same as calling both e.preventDefault and e.stopPropagation on the passed jQuery.Event object. e.preventDefault() will prevent the default event from occuring, e.stopPropagation() will prevent the event from bubbling up and return false will do both. Note that this behaviour differs from normal (non-jQuery) event handlers, … Read more