document queryselector vs document getelementbyid

Solutions on MaxInterview for document queryselector vs document getelementbyid by the best coders in the world

showing results for - "document queryselector vs document getelementbyid"
Jarrod
04 May 2016
1With a querySelector statement,
2you can select an element based on a CSS selector. 
3This means you can select elements by ID, class, or any other type of selector. 
4Using the getElementById method, you can only select an element by its ID.
5
6Generally, you should opt for the selector that most clearly gets the job done.
7
8If you only need to select an element by ID or class, 
9you can use getElementById or getElementsByClassName, respectively. 
10If you need to use a more elaborate rule to select elements, 
11the querySelector method is your best option.