How to hide two DIVs inside one another with JavaScript?

0

I am facing a problem when trying to hide two DIVs, that is, one inside the other. I can only hide one DIV and another is visible.

Here's what I'm using:

Java Script:

<script type="text/javascript">
function superpopgv(guaraparivirtualsuperpopup) {

    if(document.getElementById(guaraparivirtualsuperpopup).style.display=="none") {
        document.getElementById(guaraparivirtualsuperpopup).style.display = "inline";
    }
    else {
        document.getElementById(guaraparivirtualsuperpopup).style.display = "none";
    }

}
</script>

CSS:

#guaraparivirtualsuperpopup {
    position:relative;
    width:1215px;
    height:500px;
    background-color:#000000;
    /* background-image:url(http://www.guaraparivirtual.com.br/Lay_Out/dr-bruno.jpg);
    background-repeat:no-repeat;
    background-position:50% 50%;
    */
    margin: 0 auto;
    z-index: 9;
    border: 1px solid #EA8419;
}
#guaraparivirtualsuperpopupbtn {
    width:100px;
    height:36px;
    background-image:url(http://www.guaraparivirtual.com.br/img-novo/fechar.png);
    background-repeat:no-repeat;
    float:right;
    position: relative;
    z-index: 9999;  
}

DIV's

<div class="guaraparivirtual-topo-100-barra-inferior">

<a href="#" onclick="javascript: superpopgv('guaraparivirtualsuperpopup');" >
<div id="guaraparivirtualsuperpopupbtn"></div>
</a>

<a href="<?php echo $linkbannerrt; ?>" target="_blank" title="Super Pop-Up" / >
<div id="guaraparivirtualsuperpopup" style="background-image:url(superpopup/<?php echo $rt; ?>);"></div>
</a>

</div>
    
asked by anonymous 08.08.2016 / 16:29

1 answer

0

Note: getComputedStyle(el) will return the current styles of the element, which makes it better to get the display of the element.

The problem is that you are declaring "#guaraparivirtualsuperpopupbtn" and + elements outside the "#guaraparivirtualsuperpopup" div. Your code needs a new structure to fit all those items out of% main%. Actually this is not a problem, but nothing is happening with the elements outside the div main. Your% of parent% is being treated as a child.

    
08.08.2016 / 19:06