Sunday, July 28, 2019

javascript - onclick closing other onclicks



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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...