tags:

views:

39

answers:

2

i have divs with class "someclass" each div has chiled divs with class "otherclass"

i need to check if the divs with "otherclass" are display:none then fadeout the parent with "someclass"

how can i do it every time i click on some checkbox on the page?

+2  A: 
$(':checkbox').click(function(){

  if( $('.otherclass').css('display')=='none' ){

    $('.otherclass').parent().fadeOut('normal');

  }

}

This is assuming .otherclass is a unique identifier. Also, if you want to to link these elements to the checkbox that is clicked with, say, the same class it's a little more involved.

$(':checkbox').click(function(){

  var el = $(this).attr('class'); //Better to use a unique ID here

  if( $('div.' + el).css('display')=='none' ){

    $('div.' + el).parent().fadeOut('normal');

  }

}
jeerose
+1 - Ain't JQuery grand? Think about how much Javascript you'd have to write to do this!
Mark Brittingham
Sorry, not to be rude or anything. But this is just bad jQuery. If it should work, .attr should be .css. And still, why use .css, when jQuery has a selector for it? :-)
Kordonme
Oh, good call on the attr @Kordonme. I'm fixing it. As far as bad jQuery, yes, you've done it using a selector. I'm trying to project into the future and assume he wants to associate these elements to the checkbox. Maybe i'm wrong.
jeerose
A: 
$(":checkbox").click(function() {
    if(!$(".otherclass:visible").length)
        $(".someclass").fadeOut();
});
Kordonme