Is there a way to make a button within a newly activated div close it? The existing code seems to have issues with this functionality, and adding new rules or functions has not solved the problem. Any assistance with fixing this issue using vanilla JavaScript would be greatly appreciated.
var infoBtn = document.getElementsByClassName("more-info");
var i;
for (i = 0; i < infoBtn.length; i++) {
infoBtn[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
})
}
.work-projects {
margin: 40px 0;
}
.work-boxes {
display: flex;
position: relative;
flex-direction: column;
align-items: center;
justify-content: center;
width: 90%;
height: 40vh;
min-height: 300px;
margin: 20px auto;
background-color: white;
border-radius: 5px;
}
.work-box-content {
opacity: 1;
z-index: 1;
background-color: rgb(32, 32, 32);
padding: 20px;
width: 50%;
border: 5px solid rgba(253, 225, 78);
border-radius: 5px;
position: relative;
}
.work-projects h2 {
color: turquoise;
text-align: center;
font-weight: 400;
font-size: 1.2em;
}
.work-box-content .code-logo {
flex-direction: row;
align-self: center;
justify-content: space-around;
max-width: 100%;
}
#PHP-pic {
height: auto;
margin: auto 0;
}
.project-links {
display: flex;
justify-content: space-between;
}
.project-links img {
height: 30px;
width: auto;
transition: all .2s ease-in-out;
}
.project-links a {
padding: 20px;
text-decoration: none;
margin: 5px 0;
}
.project-links a:hover img {
filter: opacity(60%);
transform: scale(1.1);
}
.sidenav {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: 0 5px;
z-index: 200;
margin: 0;
background-color: turquoise;
text-align: center;
max-height: 0;
overflow: hidden;
transition: max-height 0.25s ease-out;
}
.more-info {
height: 30px;
width: auto;
display: block;
padding: 5px;
margin: 0 auto;
}
.sidenav p {
font-size: 0.7em;
}
<main class="main-page">
<div class="work-projects" id="work-bookmark">
<div class="work-boxes" id="sectionone">
<div class="work-box-content">
<h2>TITLE</h2>
<div class="code-logo">
<figure>
<img id="HTML-pic" src="./images/HTML5.png" alt="HTML">
</figure>
<figure>
<img id="CSS-pic" src="./images/CSS3.png" alt="CSS">
</figure>
<figure>
<img id="JS-pic" src="./images/JS.png" alt="JS">
</figure>
<figure>
<img id="PHP-pic" src="./images/php.png" alt="PHP">
</figure>
</div>
<section class="project-links">
<a class="github-project" href="https://github.com/adraf/Dan-Batchelor">
<img src="./images/iconmonstr-github-2.png" alt="github logo">
</a>
<a class="linktoproject" href="http://danbatch.com/">
<img src="./images/iconmonstr-share-11.png" alt="website link">
</a>
</section>
<img class="more-info" src="./images/iconmonstr-info-1-240.png" alt="more information">
<div id="mySidenav" class="sidenav">
<p>
Text tetxt text Text tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt text
text
<br> Text tetxt text Text tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt textText tetxt text</p>
</div>
</div>
</div>
</div>
</main>