我想使用纯JavaScript来检查HTML5数据属性是否存在。
我尝试了下面的代码片段,但它不起作用。
if(object.getAttribute("data-params")==="undefined") {
//data-attribute doesn't exist
}
if(object.getAttribute("data-params")==="undefined") {
//data-attribute doesn't exist
}
if(typeof obj["data-attribute"] !== "undefined"){ // code here }
- Ashish Kumar