I have multiple div elements on my page, which have the display switch function .
onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'"
onclick="if(document.getElementById('spoiler2') .style.display=='none') {document.getElementById('spoiler2') .style.display=''}else{document.getElementById('spoiler2') .style.display='none'}"
I am looking for a way to close each other opened element when opening a new one, so that only one can stay open.
Thanks
Answer
It's pretty hard to understand without looking at your html, but you can try something like this:
$(document).ready(function() {
$("#light").on("click", function() {
$("#spoiler2").hide();
$(this).show();
});
});
No comments:
Post a Comment