Is this the answer you were hoping to find?
How to use jQuery to select a class or ID
$(document).ready(function() {
$('#mybtn').click(function() {
$('#mymodal').show();
})
$('#mymodal .close').click(() => {
$('#mymodal').hide();
})
})
Note: I am selecting the mybtn ID, which is unique in the current HTML file. I am also selecting the close class within the mymodal ID to ensure no other close class is affected (if any exist). Here, I am opening and closing a modal.
The following code is using JavaScript
const mymodal = document.getElementById('mymodal');
const close = document.querySelector('#mymodal .close');
const mybtn = document.getElementById('mybtn');
mybtn.addEventListener('click', () => {
mymodal.style.display = 'inline';
})
close.addEventListener('click', () => {
mymodal.style.display = 'none';
})