Jquery:如何检查元素是否有一定的css类/样式 [英] Jquery: How to check if the element has certain css class/style

查看:84
本文介绍了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 ...
}

这篇关于Jquery:如何检查元素是否有一定的css类/样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆