Reputation: 17
<body>.
<section class="apply-me1">.
</section>.
<section class="apply-me2">.
</section>.
<a class="except-me" href="#">Something here</a>.
</body>
Now I want to apply some rules on all elements except the a tag using css and javascript not jquery.
I Tried this:
CSS:
body {
some rules here
}
body >*:not(.except-me).active {
some rules here
}
Javascript:
selectBody = document.getElementsByTagName('BODY')[0];
selectBody.addEventListener('click', () => {
selectBody.classList.toggle('active');
})
Basically I want to switch classes on body so some rules can be applied on all elements except the a tag when I click on body.
How can I do it ?
Upvotes: 0
Views: 1672
Reputation: 1792
You can simply use querySelector(). What you must pass in the braces is a css selector. a sample here :
document.querySelector('body >*:not(.except-me).active');
This will help you a lot. Don't forget that you MUST put a css selector in the braces.
Upvotes: 1