HTML DOM Document querySelector()
HTML DOM Document querySelector() Method
The querySelector() method is used to return the first element that matches the CSS selector. For returning all matches, we have to use querySelectorAll(). It will throw an SYNTAX_ERR exception if selectors are invalid.
Syntax:-
Its syntax is:- document.querySelector(CSS selectors)
Return:-
Its return is:- first element object that matches the CSS selector.
Further Explanation:-
Parameter | Description |
CSS selectors |
Required. One or more CSS selectors. For multiple selectors, separate each selector with a comma. |