News for hackers. Stuff that matters.
Re:Native equivalents of jQuery functions by mcbridematt on Monday May 20, 2013 @07:19AM (#5736981)
Interesting 'innerHTML' is mentioned as a crappy native equivalent. In theory, I agree. But last time I compared innerHTML vs DOM fragments, innerHTML was much much faster across the browsers I tried (this was just before JITs for JS became common place). The tradeoff it seems is the browsers native HTML parser and serialization vs holding a DOM tree in JS, and for large sets at least, innerHTML won handily.
Re:Native equivalents of jQuery functions by laughinghan on Monday May 20, 2013 @07:28AM (#5737014)
That has been my experience as well, in fact, I believe the native DocumentFragment code should be slower than the jQuery innerHTML-based code.
Re:Native equivalents of jQuery functions by ivanca on Monday May 20, 2013 @07:31AM (#5737024)
Is not crappy because is slower, is crappy because it destroys all the eventListeners and custom properties of all their childNodes.
Re:Native equivalents of jQuery functions by brokenparser on Monday May 20, 2013 @08:09AM (#5737167)
It's crappy because it's not just slow, it manages to freeze Firefox 22 on a 2,8GHz CPU.

http://jsperf.com/leebrimelow-native-methods-jquery-dom

Re:Native equivalents of jQuery functions by ivanca on Monday May 20, 2013 @08:49AM (#5737382)
At least we agree is crappy. BTW sorry for ruining your perfs, I really wanted to test some few things.
Re:Native equivalents of jQuery functions by brokenparser on Monday May 20, 2013 @09:09AM (#5737484)
Okay. Revision 9 adds code to remove the inserted elements, to put every test on equal footing. Is the practical equivalent yours? Because it hits a sweet spot.
Re:Native equivalents of jQuery functions by ivanca on Monday May 20, 2013 @09:35AM (#5737618)
The one called "MUCH MORE PRACTIVAL native equivalent" is a mistake, it doesn't do anything. I didn't know documentFragment lacks the innerHTML property so is not doing any parsing like the others.
Re:Native equivalents of jQuery functions by brokenparser on Monday May 20, 2013 @10:33AM (#5737877)
Ah, that explains it. I can't submit Firefox results, though. The crappy native equivalent just locks up after throwing several "unresponsive script" warnings.
Re:Native equivalents of jQuery functions by alisey on Monday May 20, 2013 @12:44PM (#5738548)
By using innerHTML you lose event bindings of all elements in the container you're appending data to, and the state of inputs.
Re:Native equivalents of jQuery functions by rmrfrmrf on Monday May 20, 2013 @11:00AM (#5738002)
innerHTML isn't W3C compliant. Why are you using it in the first place?
Re:Native equivalents of jQuery functions by Encosia on Monday May 20, 2013 @11:34AM (#5738169)