I have a question regarding nested divs and applying classes. In my project I have a div with an id of "content" and inside it a div with an id of "imagewrap" which itself contains and image and some other elements. Here is the html:
<div id="content">
<div id="imagewrap" class="notVisible">
<img src="Images/Image1.jpg" id="front" />
<div id="previous" class="buttons" onclick="change(-1);"></div>
<div id="next" class="buttons" onclick="change(1);"></div>
</div>
</div> <!-- end of content -->
I want that image to fade in so I have added a class of "notVisible" to the div "imagewrap" and I got some jQuery removing this class and adding a class of "visible" after a delay. js and css:
css
#content {
height: 100%;
width: 100vw;
background-color: white;
min-height: 580px;
text-align: center;}
#imagewrap{
position: relative;
z-index: 5;
display: inline-block;
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;}
.notVisible {
opacity: 0;}
.visible {
opacity: 1;
transition: opacity 0.7s ease-in-out;}
js:
function showPicture() {
$( "#imagewrap" ).removeClass( "notVisible" );
$( "#imagewrap" ).addClass( "visible" );
}
setTimeout(showPicture, 7000);
This works as expected. Just to test, I have tried adding the class "notVisible" to the div "content" instead and changing the function showPicture() like so:
function showPicture() {
$( "#content" ).removeClass( "notVisible" );
$( "#content" ).addClass( "visible" );
}
and this also works with the image fading in. The problem I encounter is that I want now to restructure my html by nesting my "content" div in a tag with an id of "container", like so:
<section id="container">
<div id="content">
<div id="imagewrap" class="notVisible">
<img src="Images/Image1.jpg" id="front" />
<div id="previous" class="buttons" onclick="change(-1);"></div>
<div id="next" class="buttons" onclick="change(1);"></div>
</div>
</div> <!-- end of content -->
</section> <!--end of container-->
and when I do this, the image stops fading in. I have tried applying the class of "notVisible" to the "container" div instead and changing the showPicture() function accordingly and it doesn't work. Why is this not working? Thanks for your time.