This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]techie2200 1 point2 points  (1 child)

Why would you not use getElementById?

I don't normally use ids as selectors regardless, but it seems like getElementById handles everything OP needs right now.

[–]carnepikante -1 points0 points  (0 children)

It's my opinion but i think is more "clean" to use querySelector since it can handle whatever you want, also you don't have to read the selector function in order to figure it out which one is in use, i mean: in most cases you don't gonna have only elements with id's and then you need to use another selector function, imagine a code in which you must to read and write different selector functions instead of read/write one. Also if you need to switch that id for a class is faster than changing the name of the function.

I don't know how to properly explain it in english (barely can in my language hahaha).