I have a webpage with a layout of multiple divs in a gridlike arrangement that all are going to contain separate text. When clicked, I want the grid to expand into a div that is z-indexed above the other elements. on click of this div, it will close.
The thing is, I do not want to make a separate function for each one of the divs, instead I want to make a generic function that will recognize which div is being clicked, and then access the divs child paragraph element and toggle that. (There is also an img within the div).
here is a cut of the HTML with the overall format that the other sections follow.
<div id="Section" onclick="portfolio()">
<h6 class="number">2. Stand Up Jetski</h6>
<img src="../resources/images/icons8-paper-ship-100.png"
alt="Brake Disc"
id="click-image">
<p class="popuptext" id="jetski-text"> random </p>
</div>
<div id="Section" onclick="portfolio()">
<h6 class="number">3. PC build</h6>
<img src="../resources/images/icons8-workstation-100.png"
alt="Brake Disc"
id="click-image">
<p class="popuptext" id="pc-text"> random </p>
</div>
Here is the javascript I came up with from internet searches.
//Portfolio Pop ups//
function portfolio() {
parent = document.getElementById('Section');
children = parent.children[0];
children.classlist.toggle('show')
}
Here is the CSS I have for these popup texts
.popuptext {
border : 1px solid var(--black);
z-index : 100;
position : absolute;
left : 50%;
top : 50%;
margin-left : -500px;
margin-top : -50px;
height : 1000px;
width : 1000px;
visibility : hidden;
}
.popuptext .show {
visibility : visible;
}
As explained earlier, when I click the div, I want the
child element to toggle visibility. So far, when I click, nothing happens.