How to delete a specific class from querySelectorAll?

Asked

Viewed 55 times

2

I am working on a project where I use bootstrap modals, for a problem of overlapping some elements, I needed to use a script that always assigns the highest value z-index +10 from the page to the new modal opened, so there is no such problem.

I happen to be using another plugin that shows notifications at the top of the screen, and notifications are getting behind the modal.

To get the biggest z-index of the page I use the following code:

var zIndex = Math.max.apply(null,Array.prototype.map.call(document.querySelectorAll('*'), function (el) {
    return +el.style.zIndex;
})) + 10;

Is there any way to keep picking all selectors (*) except the class .notifications with the .querySelectorAll() ?

  • 2

    Try to use not to delete, something like: querySelectorAll('*:not(.notifications)')

  • @Lucascosta Perfect, thanks.

1 answer

2


Usa not: CSS pseudo-class:

document.querySelectorAll('*:not(.notifications)');
  • 1

    Worked perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.