The querySelector() method in HTML is used to return the first element that matches a specified CSS selector(s) in the document.
Note: The querySelector() method only returns first element that match the specified selectors. To return all the matches, use querySelectorAll() method.
Selectors are the required field. It Specifies one or more CSS selectors to match the element. These selectors are used to select HTML elements based on their id, classes, types, etc.
In case of multiple selectors, a comma is used to separate each selector. The element which occurs first in the document is the returned element.
After click on the button:
Supported Browsers: The browser supported by querySelector() method are listed below:
- Google Chrome 4.0
- Internet Explorer 8.0
- Firefox 3.5
- Opera 10.0
- Safari 3.2