Jquery:如何检查元素是否有一定的css类/样式

问题描述:

我有一个div:

<div class="test" id="someElement" style="position: absolute"></div>

有任何方法检查某个元素:

Is there any way to check if the certain element:

$("#someElement") 

有一个特定的类(在我的情况下,测试)。

has a particular class (in my case, "test").

或者,有没有办法检查en元素有一定的风格?在这个例子中,我想知道元素是否有position:absolute。

Alternately, is there a way to check that en element has a certain style? In this example, I'd like to know if the element has "position: absolute".

非常感谢!

if($('#someElement').hasClass('test')) {
  ... do something ...
}
else {
  ... do something else ...
}