How do I write this if condition with Jquery?

This question already has an answer here:

  • Detect if an element is visible [duplicate] 3 answers

  • You can also check the following condition :

    if($('#knd').css('visibility') === 'visible') {
        $("#wars").animate({
            opacity:'0'
        }); 
    }
    

    Suggested solution:

    if($('#wars').css('opacity') === '0') {
        $("#wars").animate({
            opacity:'1'
        }); 
    }
    

    您可以使用.is()以及:可见选择器:

    if($('#knd').is(':visible')) {
        $("#wars").animate({
            opacity:'0'
        }); 
    }
    

    You can use .is(':visible') but you can use fadeToggle() or slideToggle() .

    *Toggle() function automatically does what you're intending to do, with effects .

    链接地址: http://www.djcxy.com/p/83532.html

    上一篇: 在父元素中查找可见的类元素

    下一篇: 如果使用Jquery条件,我该如何写这个?