Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding an exception for querySelectorAll

Say I got something like this:

function one() {
    var findthemall = document.querySelectorAll("*");
    var i;
    for (i = 0; i < findthemall.length; i++) {
        //doin' some cool stuff
    }
}

Now, I know I can list more than one tag in querySelectorAll using comma between them, but is there a simple way to make an exception for some specific classes/tags?

Like: querySelectorAll("*, but not p and br tags")

like image 604
franenos Avatar asked Sep 08 '25 01:09

franenos


2 Answers

Yes, the method .querySelectorAll() accepts CSS3 selectors, which means that you can use the :not() pseudo class to negate certain elements.

In this case, the selector *:not(p):not(br) would negate br and p elements.

document.querySelectorAll("*:not(p):not(br)");
like image 130
Josh Crozier Avatar answered Sep 10 '25 04:09

Josh Crozier


https://developer.mozilla.org/en-US/docs/Web/CSS/:not

document.querySelectorAll("*:not(p):not(br)")
like image 38
Juan Mendes Avatar answered Sep 10 '25 02:09

Juan Mendes