Reputation: 7788
I have a button like bellow
<input type="button" value="check" />
And,I try to alert on this button click as follows
document.querySelector('input[type="button"]').attachEvent('onclick', function() { alert(1); });
But this is not working,Why?
Upvotes: 1
Views: 188
Reputation: 1477
Use this code snippet:-
document.querySelector('input[type="button"]').addEventListener('click', function() { alert(1); });
Upvotes: 1
Reputation: 869
Maybe this ones help:
link: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_addeventlistener_crossbrowser
doc: http://www.w3schools.com/jsref/met_document_addeventlistener.asp
Upvotes: 0