by oneeyedpigeon · 11y ago · 0 comments
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
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.
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.
[].map.call(document.querySelectorAll(".foo"), function(node) { node.classlist.remove("bold"); }) [...document.querySelectorAll('.foo')].forEach(node => node.classList.remove('bold')); 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...