Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Better and shorter syntax, plugins, ecosystem.

Hide Show

```

$(".box").hide();

$(".box").show();

vs

document.querySelector(".box").style.display = "none";

document.querySelector(".box").style.display = "block";

``` Both work. The first is more clear



```

const $ = document.querySelector.bind(document);

$('.box').hidden = true;

$('.box').hidden = false;

```


1. Not really.

jQuery is designed not to fail. So if there's no `.box` on the page, jQuery will not do anything.

`querySelector` may return null, so `$('.box').hidden` will hard break your page if you're not careful enough

2. `$('.box').hide()` is just one such example.

The hilarious https://youmightnotneedjquery.com/ shows that jQuery remains more consistent, concise, and composable than most things in modern browser APIs


jumping in on this bandwagon... I sometimes look https://youmightnotneedjquery.com when I forget how to do something with jQuery.

Also, do you know if there is a jQuery-like that actually throws exceptions? Having `$('.box').hide()` tell me there is no `.box` would be pretty useful.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: