Re:The Future of JQuery UI and JQuery Mobile
by bijection on Thursday December 21, 2017 @04:59PM
(#15983196)
To make that work for all elements of that class, you could rewrite it as
The jQuery is still shorter, but the vanilla js is definitely manageable.
[ Parent
| on HN ]
Re:The Future of JQuery UI and JQuery Mobile
by tracker1 on Thursday December 21, 2017 @06:23PM
(#15983865)
Array.from(document.querySelectorAll('.myclass'))
.forEach(el => el.style.display = 'block')
Re:The Future of JQuery UI and JQuery Mobile
by collinmanderson on Thursday December 21, 2017 @07:13PM
(#15984117)
Though ie11 doesn't have Array.from()
Re:The Future of JQuery UI and JQuery Mobile
by bonesss on Friday December 22, 2017 @04:38AM
(#15986310)
Hrmmm... maybe someone should make a library that would smooth over browser differences and provide a consistent element selection syntax? Call it JavascriptSelection, or jSelection?
Re:The Future of JQuery UI and JQuery Mobile
by emergie on Friday December 22, 2017 @09:09AM
(#15987497)
imho 'JavascriptQuery' or 'jQuery' sounds better, oh wait...
Re:The Future of JQuery UI and JQuery Mobile
by tracker1 on Wednesday December 27, 2017 @05:13PM
(#16018498)
I tend to polyfill older browsers, Array.from is a pretty small one. Sad thing is at a point where it's probably worth it to have 2-3 builds in place... 1 for legacy browsers, one for modern without modules, and one for modules/import/http2 support.
Just haven't taken the time... at least the main app I work on at work doesn't need to support IE11. Latest Edge,, Firefox, Safari and Chrome ... and Chrome is the primary target.
Re:The Future of JQuery UI and JQuery Mobile
by no_gravity on Thursday December 21, 2017 @05:12PM
(#15983321)
Unfortunately, querySelectorAll returns a NodeList, not an Array. So you cannot use forEach() on it.
Re:The Future of JQuery UI and JQuery Mobile
by hawkice on Thursday December 21, 2017 @05:15PM
(#15983347)
NodeList also implements forEach:
https://developer.mozilla.org/en-US/docs/Web/API/NodeList/fo...
Re:The Future of JQuery UI and JQuery Mobile
by collinmanderson on Thursday December 21, 2017 @05:16PM
(#15983357)
It's a very recent addition. IE11 doesn't have it for sure.
Re:The Future of JQuery UI and JQuery Mobile
by no_gravity on Thursday December 21, 2017 @05:18PM
(#15983367)
Not in Edge though.
Re:The Future of JQuery UI and JQuery Mobile
by hawkice on Thursday December 21, 2017 @05:24PM
(#15983409)
The page I linked has a compatibility chart that says Edge 16 has it (no idea if that's a planned release, haven't ever used Edge).
Re:The Future of JQuery UI and JQuery Mobile
by darepublic on Thursday December 21, 2017 @06:18PM
(#15983819)
You can use Array.prototype.forEach.call(nodelist, fn), or Arrays.from(nodelist).forEach
Re:The Future of JQuery UI and JQuery Mobile
by panzi on Thursday December 21, 2017 @11:24PM
(#15985267)
I don't use Windows so I can't test it, but would this work as a polyfill?
NodeList.prototype.forEach = Array.prototype.forEach;
In Chrome this even returns true: NodeList.prototype.forEach === Array.prototype.forEach