Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Apply class to neighbor div when div gets class

I have a div containing all my content, and then I have a div containing pop-up windows. So basically something like this:

<div class="content">
    Some content
</div>

<div class="popup-wrapper">
    Popup content
</div>

Then at some point a class is added to the popup-wrapper due to some button click, that in Angular would look something like:

<button (click)="popup = !popup">Click me</button>

<div class="popup-wrapper" [ngClass]="popup ? 'is-active' : ''">
    Popup content
</div>

My question is: Are there some way (CSS wise. JS would probably also do if no other alternative is available) that when popup-wrapper has the class is-active I can also target content as well ?

The issue for me not just putting the same JS into the content div, i.e. [ngClass]="popup ? 'is-active' : ''" is because there are several instances that can activate a popup, and other popup wrappers as well. So if I were to do this I would have to go through every page that has this kind of popup-wrapper, and paste similar code into every content div, but with different state names.

So I just thought it would be much easier, if I could target the content div whenever the popup-wrapper div had the is-active class.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For my understanding, you'll need something like that:

function anyName () {
  let x = document.getElementByClassName('is-active');
  if (x === true) {
    // do something
  }
}

Depending on what ever you want to do next, you can either go for an identifier like your div's className ('content') or you try to target it by its position, like 'previousElementSibling'

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!