Learn HTML DOM
Accessing DOM Elements
3.4
Lesson

Selecting DOM Elements Using querySelector

querySelector will select the first HTML element which matches the provided query and ignore the rest. This is a versatile selector and can match the element using any of the CSS selectors, including class name, tag name, id name or any complex selector too.

The selectors that we pass in this method are simply the CSS selectors that we have used in CSS. This means you can use # to select using the id, . to select the elements using their class and you can go as detailed as possible with your selectors. This can be seen in the example given above for the case of inspirationConfirmation.