I am trying to display different popups based on randomly generated ids. The code I am using is as follows (this is done using Toolset Types in WordPress):
<div class="id-select" id="[random_number]">
<div class="service-container">
<div class="service-image">
[types field="picture"][/types]
</div>
<div class="service-text">
<p><strong>Item:</strong> [wpv-post-title output="sanitize"]</p>
<p><strong>Suitable For:</strong> [wpv-post-taxonomy type="memorial-category" format="name"]</p>
<p><strong>Price:</strong> [types field="price"][/types]</p>
</div>
</div>
</div>
<!-- The Modal -->
<div id="myModal-custom" class="modal-custom">
<!-- Modal content -->
<div class="modal-content-custom">
<span class="close-custom">×</span>
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<div class="service-image">
[types field="picture"][/types]
</div>
</div>
<div class="col-md-6">
<div class="service-text">
<p><strong>Item:</strong> [wpv-post-title output="sanitize"]</p>
<p><strong>Suitable For:</strong> [wpv-post-taxonomy type="memorial-category" format="name"]</p>
<p><strong>Price:</strong> [types field="price"][/types]</p>
</div>
</div>
</div>
</div>
</div>
</div>
The JavaScript is as follows:
// Get the modal
var modal = document.getElementById('myModal-custom');
// Get the button that opens the modal
var ids = [];
$('.id-select').each(function(i, el) {
if (el.id == '') {
return;
}
ids.push('#' + el.id);
});
//console.log(ids.join(','));
$(ids.join(',')).on('click', function(e) {
modal.style.display = "block";
})
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close-custom")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
The problem im having is that any item i click on the front-end displays the same modal box. Is there anyway I can get it to pick up the correct modal box for a specific item?
The live site - http://79.170.40.172/tc-pinkfin.co.uk/memorials/cemetery/