+ 14
querySelector vs getElementByID
What is the difference between querySelector and getElementById
5 Antworten
+ 10
getElementById selects an element by its id name while querySelector selects an element by tag name, id name and class name like this
querySelector('tag')
querySelector('.class')
querySelector('#id')
+ 7
So it is better to use querySelector rather than getElementById.
+ 2
querySelector has more options where as getElementById is specific to id defined. These are not supported in IE6-7 if i am not mistaken.
+ 2
I find this useful to check browser compatibility. www.caniuse.com
+ 2
https://code.sololearn.com/WOx16Bf9u6KK/?ref=app
https://code.sololearn.com/WvN162f7Czk8/?ref=app
the query string of querySelector can be combined
https://code.sololearn.com/WzVH8V29oi4H/?ref=app