3 ms·
didn't know: - setting innerHTML is faster than dom manipulation - doing dom node manipulation is faster off dom (reinsert when manip is done) - is attaching
by staticshock 19y ago
didn't know:
- setting innerHTML is faster than dom manipulation
- doing dom node manipulation is faster off dom (reinsert when manip is done)
- is attaching a 'click' event listener really that much slower than setting node.onclick?
disagree:
- onmousedown and onclick are different actions. onclick is inherently slower because it doesn't fire until after onmouseup. the difference is not 100ms, it's however long the user holds the mouse button. onmousedown should not commit the user to the action, since the user may decide not to do the action and needs a way to cancel it and void the action (ie: move the mouse off the target area before clicking). onmousedown, on the other hand, is an immediate commitment, so it can't be used for dangerous actions that the user may regret a split second later.
- axod 19y agoinnerHTML is also really really evil. Apart from making for horrible ugly code, it plain doesn't work for many things (tables/forms have issues). I'd take many of the points with a pinch of salt. Use profilers, and other debug methods to find out what works/doesn't work in your code. For example the point about event listeners vs setting node.onclick. Perhaps it is marginally quicker. But will the user notice unless you add 1,000 event listeners? Unlikely. Might not even notice then. It all depends on where and how it's used. Also obviously you can't use .onclick if you want several event handlers attached to the same event unless you do that functionality yourself.
- boucher 19y agoi recall reading elsewhere (and verifying) that the dom node manipulation thing isn't actually faster, but i can not find it at the moment.