3 ms·
jQuery is really useful when it comes to DOM manipulation, obviously. Without using any framework you'll find yourself iterating over NodeLists all over the pl
by g00gler 9y ago
jQuery is really useful when it comes to DOM manipulation, obviously.
Without using any framework you'll find yourself iterating over NodeLists all over the place.
ie, it's much cleaner to write
$('p').css('color', 'blue');
Than
document.querySelectorAll('p').forEach(el => el.style.color = 'blue');
Also, Microsoft kinda screwed us by keeping IE 11 around until 2025.
- tenryuu 9y agoCode cleanliness matters more so in a compiled language. Having an interpreted language means, regardless of how long it takes you to write, everything has to be downloaded/processed on every single execution of the file. Putting more effort into my code to remove unnecessary libraries allows the end user to load pages faster, and that's what I think matters most, because I hate having to wait, sometimes even twenty seconds for some simple pages to pass a loading screen
- megous 9y agoYou can create a trivial helper function such as: let $ = s => document.querySelectorAll(s); And then use: for (let p of $('p')) p.style.color = 'blue'; And if you start doing anything more complex per iteration: $('p') .css('color', 'blue') .addClass('bla') .filter(function() { $(this).parent().is('article'); }) .removeClass('qwe'); The code becomes much less magical and clearer (it's almost self explanatory): for (let p of $('p')) { p.style.color = 'blue'; p.classList.add('ble'); if (p.parentNode.matches('article')) p.classList.remove('qwe'); } Also much more debuggable in a debugger, and faster, as you're iterating only once and are not calling many needless functions.
- g00gler 9y agoVery true, nice codes :). Would be nice if we could write that without transpiling.