How do I write this if condition with Jquery?
This question already has an answer here:
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 .
上一篇: 在父元素中查找可见的类元素