What is the querySelector?

What is the querySelector method in Javascript and how to use it?

The querySelector helps you to find first first element that matches css selector you specify. So basically it lets you find html elements.

const header = document.querySelector("h1");
You can also use # (hash means id).
const myid = document.querySelector("#myid");

To search a class use a dot.

const myClass = document.querySelector(".class");

queryselector javascript

Leave a Reply

Your email address will not be published. Required fields are marked *