4 ms·
I think the more direct comparison is document.querySelector('#element').style.display = 'none' That has the same ergonomics as the jQuery selector, and is ju
by marcolussetti 4y ago
I think the more direct comparison is
document.querySelector('#element').style.display = 'none'
That has the same ergonomics as the jQuery selector, and is just a bit longer. I feel like with editors that autocomplete, it's not enough of a difference to warrant the extra dependency.
- deleted 4y ago[deleted]
- hbn 4y agoI think the vanilla JS is better actually, because I actually know what it's doing. I've never used JQuery before and would have assumed calling .hide() on an element would set the CSS attribute "visibility: hidden" rather than "display: none"
- yyyk 4y ago>That has the same ergonomics as the jQuery selector Nitpick: This crashes if #element doesn't exist, while the jQuery one does not. Also, the jQuery selector is a tiny bit more powerful (:even, :odd). IMHO, jQuery is good for what it's built for - a nicer interface than vanilla - but the main use case is much less needed now that frameworks exist.
- MrJohz 4y agoI don't know if that's such a good nitpick in practice. I want my code to crash if my assumptions aren't true - especially if I'm in the process of developing the code, I want to see big red errors and stack traces that point directly to the line that failed. If it's meant to be the case that the element may or may not be present, then I'd much rather see an explicit check for that, than assume one thing and find out another later.
- zamadatix 4y agoThe same power exists, again a bit longer, :nth-of-type(odd).
- jacobsenscott 4y agoA but fugly, ?. helps - document.querySelector('#element')?.style?.SetPropery('display', 'none')