I want the button with the class name of "x-1" to give the div with the class name of "popup-1" a display property of "none". and "x-2" gives the div "popup-2" a display of "none" when clicked. i have tried this and when i press "x-1" it gives a display of "none" to "popup-2" instead of "popup-1".
$(document).ready(function(){
var xCount = 2;
for (i = 0; i < xCount; i++) {
$('.x-'+i).click(function(){
$('.popup-'+i).css('display','none');
});
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="x-1">Hide popup-1</button>
<button class="x-2">Hide popup-2</button>
<div class="popup-1">popup-1</div>
<div class="popup-2">popup-2</div>