None None - 3 months ago 9
jQuery Question

How to check if even one div is expanded or all closed?

I have three expandable div, and i need condition to check if even one of them is open but i dont know how or check if all of them closed. Any help?

http://jsfiddle.net/sutekh/ku8B9/

$("#expand dt a").click(function () {
$(this).parent().siblings("dd").slideToggle();
});

Answer

If you would like to know if you have any other expanded divs you can use :visible selector

$("#expand dt a").click(function () {
    if( $('#expand dd:visible').length > 0) {
    alert('you already have opened ' +  $('#expand dd:visible').length + ' question(s)');
  }
   $(this).parent().siblings("dd").slideToggle(); 
});

will cause the alert to popup if you will try to expand two or more divs at the same time. Working fiddle: http://jsfiddle.net/ku8B9/250/