-
Notifications
You must be signed in to change notification settings - Fork 0
QuerySelector Examples
14paxton edited this page Jul 22, 2022
·
5 revisions
document.querySelectorAll('div, span')document.querySelectorAll('[data-example="test"]')document.querySelectorAll(':nth-child(4n)')document.querySelectorAll('#test li')document.querySelectorAll(‘tbody td:not(.MuiTableCell-alignRight)’)querySelectorAll(‘tr:nth-of-type(2n+1)’)<input type="checkbox" id="c2" name="c2" value="DE039230952"/>
//Replace $$ with document.querySelectorAll in the examples:
$$('input') //Every input
$$('[id]') //Every element with id
$$('[id="c2"]') //Every element with id="c2"
$$('input,[id]') //Every input + every element with id
$$('input[id]') //Every input including id
$$('input[id="c2"]') //Every input including id="c2"
$$('input#c2') //Every input including id="c2" (same as above)
$$('input#c2[value="DE039230952"]') //Every input including id="c2" and value="DE039230952"
$$('input#c2[value^="DE039"]') //Every input including id="c2" and value has content starting with DE039
$$('input#c2[value$="0952"]') //Every input including id="c2" and value has content ending with 0952
$$('input#c2[value*="39230"]') //Every input including id="c2" and value has conten
//Use the examples above directly, without the need for additional library, just by adding:
const $$ = document.querySelectorAll.bind(document);
//Some additions:
$$(.) //The same as $([class])
$$(div > input) //div is parent tag to input
document.querySelector() //equals to $$()[0] or $()