The following code allows me to toggle a div inside an LI, how can I adjust it so that when one div is open all other divs inside sibling LI’s are closed?
$(document).ready(function () {
$('.grey_button a').toggle(function() {
$(this).closest('li').find('.job_description').fadeIn(0);
$(this).toggleClass('open');
//$(this).text($(this).text() == 'More Information' ? 'Hide Information' : 'More Information');
return false;
},
function() {
$(this).closest('li').find('.job_description').fadeOut(0);
$(this).toggleClass('open');
//$(this).text($(this).text() == 'Hide Information' ? 'More Information' : 'Hide Information');
return false;
});
});
Example of HTML
<ul>
<li>
<div class="grey_button"><a href="" class="arrow">More information</a></div>
<div class="job_description" style="display: none; ">
Lorem ipsum
</div>
</li>
<li>
<div class="grey_button"><a href="" class="arrow">More information</a></div>
<div class="job_description" style="display: none; ">
Lorem ipsum
</div>
</li>
<li>
<div class="grey_button"><a href="" class="arrow">More information</a></div>
<div class="job_description" style="display: none; ">
Lorem ipsum
</div>
</li>
</ul>
You could just add one lookup for all
$('.job_description').hide().If this would impact other sections of page with same class: