Not to mention the syntax is nicer. Compare the wordy:
> document.getElementById('myid');
to
> $('#myid');
I feel the same way about underscore. Regardless of the helper functions, readability goes up.
> document.getElementById('myid');
to
> $('#myid');
I feel the same way about underscore. Regardless of the helper functions, readability goes up.
function $(sel) {
switch (sel[0]) {
case '#': return document.getElementById(sel.slice(1));
case '.': return document.getElementsByClassName(sel.slice(1));
default: return document.getElementsByTagName(sel.slice(0));
}
}
I mean... "readability".But I can understand that it's less about the user experience and more about the developer experience nowadays.
(but it would be only pseudo jQuery, the way you can have pseudo React just by using functions and ES6 template strings https://jsfiddle.net/vug86rn0/ )
var $ = document.querySelectorAll.bind(document);
$('#myid');