[英]How to check if an element with .Attr has a particular class?
這是HTML結構:
<div data-step="1"></div>
<div data-step"2" class="active"></div>
沿着這些方向的東西(以下顯然是錯誤的,它只是提供一個想法)
if($("div").attr("data-step", "2").hasClass("active")) {
//do this...
}
使用屬性equals selector來獲取具有特定屬性值的元素。 使用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.