1

If I had two <div> elements like so:

<div class="overlay"></div>
<!-- Other content here -->
<div class="popup"></div>

When div.popup has display: block I would like div.overlay to also have display: block and likewise for display: none;

Instead of using an if statement to check whether div.popup if visible, I would like to have something like an event handler.

How would I do this using jQuery? Thanks.

Pav Sidhu
  • 6,724
  • 18
  • 55
  • 110
  • _"One thing I forgot to mention I would like it to check automatically, instead of doing this with an if statement I would like something like an event handler."_ Can include how is `display` property for `.popup` is changed at `js` , `css` at Question ? What is `` at `html` ? – guest271314 Jan 10 '16 at 18:11
  • 1
    Maybe this can help you: http://stackoverflow.com/questions/1397251/event-detect-when-css-property-changed-using-jquery – Rodrigo Leite Jan 10 '16 at 18:28
  • Well? Mind showing some jQuery you currently have? P.S: why don't you simply place your popup inside overlay? – Roko C. Buljan Jan 10 '16 at 18:31

1 Answers1

0

You can do it like below. Hope this will help you.

setInterval(function() { 
    if($('div.popup').is(':visible')) {
        $('div.overlay').show();
    } else {
        $('div.overlay').hide();
    }
}, 20);
Ibrahim Khan
  • 20,616
  • 7
  • 42
  • 55