Targeting methods in Javascript (querySelector)

Posted by

querySelector       document.querySelector(CSS Selector)

querySelectorAll  document.querySelectorAll(CSS Selector)

querySelector() 

The querySelector() method returns the first Element within the document that matches the specified selector, or group of selectors. It returns only first one code

 If no matches are found, null is returned

Example:-

querySelectorAll

The querySelectorAll() method in HTML is used to return the All element that matches a specified CSS selector(s) in the document. The querySelector() method only returns the first element that matches the specified selectors. To return all the matches, use the querySelectorAll() method

Example:-

Output:-

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x