0

I need to apply style on all allements in specified area except a specified one with JS. How do I do that? I couldn't find any solutions. THank you in advance!

1
  • Can you include your code? Commented Jun 5, 2021 at 18:13

1 Answer 1

1

You could do document.querySelectorAll("parent *:not(#target')") and then add whatever style.

document.querySelectorAll('div *:not(#target').forEach((el) => el.style.color = 'red');
<div>
    <span>Hello</span> <span>World</span>
    <span>Hello</span> <span>World</span>
    <span>Hello</span> <span>World</span>
    <span>Hello</span> <span>World</span>
    <span id="target">Hello</span> <span>World</span>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I didn't know I was able to use :not etc in .querySelectorAll()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.