I have a menu with some links. Like this:
<ul id="nav"><li><a href="#" class="tartalom">Some Div 1</a></li><li><a href="#" class="tartalom2">Some Div 2</a></li></ul>
Here are my divs.
<div class="tartalom1>Bla bla bla</div>
<div class="tartalom2>Yeeah yeah yeah</div>
How to make it possible, if I click on the links to open that div with the same class and close the others if they are open? I tried this, but it wont help:
$(document).ready( function(){
$('.tartalom').click( function(){ // set of divs to be clickable
$(this).siblings('div').hide(); // it's already showing, right?
});
});
You need to reach the enclosing div first to access siblings divs. You can use closest() function to find the nearest ancestor matching the search criteria.
Live Demo
You also missed the closing quotes of
tartalom1andtartalo2class in divs.