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

There's a bunch of pretty convenient selectors that are not supported by document.querySelector(), such as :selected, :checked and a bunch of others (I forgot which exactly, but I've run in to it a few times).

In general the DOM API offends pretty much every single of my sensibilities on how to design good APIs. I also have some gripes with the jQuery API, but it's a lot better. jQuery just reads and writes so much more fluently.



:checked is standard CSS, and old.


Eh, do'h, of course. There's a few selectors anyway, but I'd have to check which ones exactly. :eq(n) and :visible from a quick check (:nth-child(n) can replace :eq(n) in some cases, but not all).


Yes, I've used :nth-of-type(n) for that too. Visibility is surprisingly messy though.


:contains(text) is useful.


`:visible` and `:hidden` are really cool


In my opinion selecting something based on it's layout is oftentimes a dangerous pattern, you are basically tying the UI layout with the logic. People can overuse these cool selectors. I've personally worked on a website where the frontend part was a spaghetti mess with the half of the source code occupied by selector names. Some files have over 5000 lines of code. It would be far less pain to maintain and implement features if the website used some framework like angular.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

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

Search: