Bling – the $ of jQuery without the jQuery
gist.github.com
Bling – the $ of jQuery without the jQuery
1–10 of 138 posts
Re: Bling – the $ of jQuery without the jQuery
#21. Alias document.querySelectorAll to $. 2. Alias node.on to node.addEventListener. 3. Make NodeList a sub-type of Array (so you can use forEach etc on node lists as you would on arrays).
The $ of jQuery also does a few other things, e.g. create HTML elements from text ($('') creates a div element with CSS class "foo") and wrap elements in a node list ($(document.body) creates a node list containing document.body).
Re: Bling – the $ of jQuery without the jQuery
#3 function $(q) { return document.querySelector(q) }Re: Bling – the $ of jQuery without the jQuery
#4This is all I personally ever need. function $(q) { return document.querySelector(q) }
function $(q, parent) { return (parent || document).querySelector(q); }Re: Bling – the $ of jQuery without the jQuery
#5On one hand it may be a nice way to show to people that what they use in jQuery can be written in a few lines of pure JS.
On the other hand it encourages people who could use pure JS (because they only use a small portion of jQuery) to stick with some non-standard helper syntax.
Re: Bling – the $ of jQuery without the jQuery
#6Yep, this submission is Hipster 1.0 Certified.
Re: Bling – the $ of jQuery without the jQuery
#7I wish that someone would write a drop-in javascript replacement for jquery in the context of bootstrap.
Re: Bling – the $ of jQuery without the jQuery
#8I don't really know what to think about that. On one hand it may be a nice way to show to people that what they use in jQuery can be written in a few lines of pure JS. On the other hand it encourages people who could use pure JS (because they only use a small portion of jQuery) to stick with some non-standard helper syntax.
Or in other words - replacing an ugly, verbose API with a widely recognised alternate syntax!
Re: Bling – the $ of jQuery without the jQuery
#9This is all I personally ever need. function $(q) { return document.querySelector(q) }
I prefer:- function $(q, parent) { return (parent || document).querySelector(q); }
function $(q, parent) {
parent = parent || document;
return [].slice.call(parent.querySelectorAll(q));
}Re: Bling – the $ of jQuery without the jQuery
#10When do you need to do that?