jQuery检查元素是否具有特定的样式属性(显示)
问题描述:
我需要在函数中包含if / else语句。如何检查元素(例如#cadrage)是否具有显示样式属性?这是我在网上发现的,但是,它不起作用..
I need to have a if/else statement inside a function. How do you check if an element (e.g. #cadrage) has a display style property? This is what I have found around the net and yet, it is not working..
if( $('#cadrage').attr('style').display == 'block' ) {
// do something
} else {
// do something
}
答
jQuery .css()函数似乎就是你想要的。
The jQuery .css() function seems to be what you want.
if( $('#cadrage').css('display') == 'block' ) {
console.log('It equal block');
} else {
console.log('It did not equal block');
}