4 ms·
In this way you can attach just one function to the event. Other way allows for more flexibility. http://www.quirksmode.org/js/events_tradmod.html http://www.q
by bd 17y ago
In this way you can attach just one function to the event. Other way allows for more flexibility.
http://www.quirksmode.org/js/events_tradmod.html http://www.quirksmode.org/js/events_tradmod.html
http://www.quirksmode.org/js/events_advanced.html http://www.quirksmode.org/js/events_advanced.html
But I guess interviewer was not implying onmouseover was "wrong", just probing how much does candidate know about the topic.
- shiranaihito 17y agoIn this way you can attach just one function to the event. Other way allows for more flexibility. Alright. To me it sounded a bit like onmouseover was used only by bad programmers.
- nostrademons 17y agoI'm kinda curious why you would ever use onmouseover when attachEvent/addEventListener are available? I just took out the remaining calls to .onEvent handlers in websearch's JS library - the only browsers that don't support the W3C/IE event models are so ancient that they don't get JS anyway, and there's not much point using a method that's unnecessary on modern browsers and does the wrong thing anyway. So yeah, my interviewer wasn't implying that onmouseover is used only by bad programmers, but I am. ;-)
- shiranaihito 17y agoMaybe I only need one event handler, or maybe I've baked a function that calls another function? Besides, I'd rather use one standard method that works across browsers than choose one based on the user's browser. Would you call that bad programming? :p Nowadays I generally use jQuery (.click(fn)) though.
- nostrademons 17y agoAh, okay. Most of the stuff I've worked on adds events through a library (eg. jQuery.click(fn)), and there's no reason for that library to use onmouseover etc.