Javascript 如何检查具有.Attr的元素是否具有特定的类?
这是HTML结构:Javascript 如何检查具有.Attr的元素是否具有特定的类?,javascript,jquery,Javascript,Jquery,这是HTML结构: <div data-step="1"></div> <div data-step"2" class="active"></div> 用于获取具有特定属性值的元素。方法只需设置属性值并返回jQuery元素对象 if($("div[data-step='2']").hasClass("active")) // or simply combine the class with selector and // check exist
<div data-step="1"></div>
<div data-step"2" class="active"></div>
用于获取具有特定属性值的元素。方法只需设置属性值并返回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)
$(“div”).attr(“数据步骤”,“2”)
设置value@LGSon我知道这是错误的,只是一个更口头的例子,试图更好地解释我在看什么for@rob.m:很乐意帮忙:)
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)