If you're looking for a solution, JQuery is a great option, but it's also possible to solve the issue using pure JavaScript alone.
Firstly, if the goal is to trigger this action on click, remove any hover attributes in your CSS. Currently, there is a hover effect defined as follows:
.photo-img:hover .photo-caption {
width: 100%;
height: 100%;
background: rgba(0,0,0,.5);
position: absolute;
top: 0;
left: 0;
display: inline-block;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10%;
background-repeat: no-repeat;
background-position: center center;
}
You can change this by creating a custom class called 'photo-caption-show' which will be toggled on click:
.photo-caption-show {
width: 100%;
height: 100%;
background: rgba(0,0,0,.5);
position: absolute;
top: 0;
left: 0;
display: inline-block;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10%;
background-repeat: no-repeat;
background-position: center center;
}
Next, create a function in JavaScript to toggle this class when clicked:
var toggleShow = function(){
var element = document.querySelector(".photo-caption");
element.classList.toggle("photo-caption-show");
}
This function targets the DOM element with the class photo-caption and toggles the specified class.
Finally, to execute this method, you can link it to the desired div, such as a div with the class a-post:
<div class="a-post" onclick="toggleShow()">
If you need to apply this functionality to multiple elements with the same class, you can loop through them using JavaScript like this (although JQuery would simplify this process). Add the following code after defining the toggleClass function:
var elements= document.getElementsByClassName("a-post");
for(var i = 0; i < elements.length; i++) {
var element= elements[i];
element.onclick = toggleClass;
}