I accidentally did the following and to my surprise it worked!
one.addEventListener('mouseover', myFunction);
I am assuming this is a shorthand way of doing the following:
document.getElementById('one').addEventListener('mouseover', myFunction);
I am wondering are the two equivalent and will this work in any browser?
答案 0 :(得分:0)
Yes this is totally possible, this is already answered in details here:
答案 1 :(得分:0)
Yes, both should work in any browser.
A truly short hand method of this would be to use jquery:
$("#one").on("mouseover", *yourfunctionname*);
or
$("#one").on("click", function(){
//your function code
});