I have div
s with class "someclass"; each div 开发者_开发知识库has child div
s with class "otherclass".
I need to check if the divs with "otherclass" are display:none
and then fadeout the parent with "someclass"
How can I do it every time I click on some checkbox on the page?
$(':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');
}
}
$(":checkbox").click(function() {
if(!$(".otherclass:visible").length)
$(".someclass").fadeOut();
});
精彩评论