[英]How to check if an element with .Attr has a particular class?
This is the HTML structure: 这是HTML结构:
<div data-step="1"></div>
<div data-step"2" class="active"></div>
Something along those lines (the following is obviously wrong, it's just to provide an idea) 沿着这些方向的东西(以下显然是错误的,它只是提供一个想法)
if($("div").attr("data-step", "2").hasClass("active")) {
//do this...
}
Use attribute equals selector to get the element with a certain attribute value. 使用属性equals selector来获取具有特定属性值的元素。 With
attr()
method it simply sets the attribute value and returns the jQuery element object. 使用
attr()
方法,它只需设置属性值并返回jQuery元素对象。
if($("div[data-step='2']").hasClass("active"))
// or simply combine the class with selector and
// check existance simply by checking its length
if($("div[data-step='2'].active").length)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.