Chrome Extension

Query selectors in Javascript

//TO SELECT THE VERY FIRST ELEMENT
var element = document.querySelector(".element_class");
//YOU CAN ALSO PASS CHILD HIERARCHY INTO IT
var child_element = document.querySelector(".element_class .child_class");

//TO SELECT ALL ELEMENTS BY CLASS YOU CAN USE BELOW QUERY SELECTOR
var all_elements = document.querySelectorAll(".element_class");

//YOU CAN SLECT ELLEMENTS BY ITS CLASS NAMEs, OR IDs, or BY USING ELEMENTS NAMES LIKE
var all_divs_opn_webpage = document.querySelectorAll("div");

QuerySelectors in javascript is used to select HTML DOM elements by class name, id or tag name. You can select one or all elements by once and manipulate them. This also supports hierarchy based elements selection like jQuery.

Search history ×