I know this is easily done in jQuery or any other framework, but that\'s not really the point. How do I go about \'properly\' binding a click event in pure javascript? I kno
The basic way is to use document.getElementById() to find the element and then use addEventListener to listen for the event.
In your HTML:
click here
In your JavaScript:
function myFunc(eventObj) {
// ...
}
var myElement = document.getElementById('some-id');
myElement.addEventListener('click', myFunc);
Or you can use an anonymous function:
document.getElementyById('some-id').addEventListener('click', function(eventObj) {
// ...
});