How to Use CSS Selector in javascript?

querySelector(“CSS Selector”)

The method querySelector() returns the first Element match of the specified selector or group of selectors. If no matches are found, null is returned.

querySelectorAll(“CSS Selector”)

The method querySelectorAll() returns a static (not live) NodeList representing a list of the document’s elements that match the specified group of selectors.

  • The NodeList object represents a collection of nodes. The nodes can be accessed by index numbers. The index starts at 0.
  • You can use the length property of the NodeList object to determine the number of elements that matches the specified selector, then you can loop through all elements and extract the info you want.
  • If the specified selectors include a CSS pseudo-element, the returned list is always empty.

querySelectorAll(“CSS Selector”)

querySelectorAll(“CSS Selector”)

More specific

querySelectorAll(“CSS Selector”)

  • Length Property
  • Loop


The innerHTML property defines the HTML content.

Tagged : / / /
0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x