News for hackers. Stuff that matters.
Re:You Don't Need JQuery by oneeyedpigeon on Tuesday December 16, 2014 @02:37PM (#8758889)
.classlist() [1] is coming [2]. It'll allow you to do:

    document.getElementById('foo').classList.remove("bold");
Sure, it's still more verbose. But a lot of what jQuery does is slowly being obsoleted by better native javascript apis.

[1] https://developer.mozilla.org/en-US/docs/Web/API/Element.cla... [2] http://caniuse.com/#feat=classlist

Re:You Don't Need JQuery by Khao on Tuesday December 16, 2014 @02:48PM (#8758960)
So when those new native api functions arrive, jQuery will start using them and gain some performance boost (using native vs. custom js code) while at the same time remaining backwards compatible (by doing feature detection). No one wants to write their own feature detection code so this whole page about using native apis is instead of jQuery is ridiculous.

If the point of that website was to educate people on the apis that jQuery calls under the hood, it chose a really poor name.

Re:You Don't Need JQuery by aplummer on Tuesday December 16, 2014 @06:45PM (#8760297)
This a thousand times, I know with $.trim it will use trim() for good browsers and then whatever hack effort was necessary for IE8. It would be devastating to have to write this manually.
Re:You Don't Need JQuery by kyllo on Tuesday December 16, 2014 @03:54PM (#8759408)
Exactly. "No one wants to write their own feature detection code" is the whole point of jQuery.
Re:You Don't Need JQuery by rip747 on Tuesday December 16, 2014 @04:45PM (#8759745)
You hit the nail on the head.
Re:You Don't Need JQuery by malandrew on Wednesday December 17, 2014 @01:39AM (#8761338)
Or you could use the class list polyfill.
Re:You Don't Need JQuery by organsnyder on Wednesday December 17, 2014 @12:19PM (#8763118)
If that's all you need, then that would be fine. However, for most projects you end up needing many other such polyfills, to the point that you might as well use one library—jQuery—to provide them all (plus a lot of other functionality).
Re:You Don't Need JQuery by bshimmin on Tuesday December 16, 2014 @02:46PM (#8758946)
Sure, the native APIs are slowly catching up, and classList is definitely a useful one.

You'd better hope that there actually is an element with an ID of "foo", though, otherwise your example will throw an exception. The last time I pointed this out here, there was some disagreement as to whether jQuery's behaviour is actually desirable. I think it is, but I'm probably biased from writing too much jQuery over the years.

Re:You Don't Need JQuery by jhpriestley on Tuesday December 16, 2014 @02:43PM (#8758929)
`$(".foo").removeClass("bold")` becomes the wonderfully concise

    [].map.call(document.querySelectorAll(".foo"), function(node) { node.classlist.remove("bold"); })
Re:You Don't Need JQuery by ahoge on Tuesday December 16, 2014 @11:39PM (#8761106)
With spread and fat arrows:

    [...document.querySelectorAll('.foo')].forEach(node => node.classList.remove('bold'));
Re:You Don't Need JQuery by sfeng on Tuesday December 16, 2014 @02:46PM (#8758945)
This may seem anecdotal, but I can tell you from writing a lot of non-jQueryified code that with modern browsers, applying classes to dozens of elements dynamically can be an anti-pattern. 99% of the time, when doing something which previously would have required that, I can use a single class on a parent element.
Re:You Don't Need JQuery by usingpond on Tuesday December 16, 2014 @02:53PM (#8758986)
Not if you're in an environment (like mobile) where you want to reduce repaint.
Re:You Don't Need JQuery by malandrew on Wednesday December 17, 2014 @01:50AM (#8761361)
In which case you don't want to be using jQuery at all and should instead be using a virtual DOM implementation like virtual-dom, famo.us, react or mithril.

https://github.com/Matt-Esch/virtual-dom

Re:You Don't Need JQuery by ulisesrmzroche on Thursday December 18, 2014 @10:12AM (#8767537)
What if you don't have the option to all of a sudden bust out a new framework? Some of these scenarios are just unrealistic.
Re:You Don't Need JQuery by ulisesrmzroche on Tuesday December 16, 2014 @05:51PM (#8760093)
No, you're going to mess with repaints and renders. It is not an anti pattern.
Re:You Don't Need JQuery by TheGunner on Wednesday December 17, 2014 @03:36AM (#8761586)
While I'm waiting for that, and still writing applications that have to support ancient versions of IE, I think I'll stick with Jquery. Can't wait for the future though
Re:You Don't Need JQuery by mcmillion on Tuesday December 16, 2014 @02:45PM (#8758941)
And in 5-10 years, we'll be able to use it.
Re:You Don't Need JQuery by taf2 on Tuesday December 16, 2014 @03:25PM (#8759224)
before jQuery I always defined an ID method like:

   function ID(id) { return document.getElementById(id); }
saved some typing. I'll always try to use jQuery now though, bigger problems to solve.. few extra bytes to download is not that bad...
Re:You Don't Need JQuery by eli on Tuesday December 16, 2014 @02:44PM (#8758932)
The day I can drop support for IE <10 will be a good day.
Re:You Don't Need JQuery by seanp2k2 on Tuesday December 16, 2014 @11:35PM (#8761092)
They said this about IE5 and 6 too.
Re:You Don't Need JQuery by eterm on Wednesday December 17, 2014 @07:20AM (#8762021)
Some of us still have to support IE6.