Home >Web Front-end >JS Tutorial >How to set and get custom attributes in js

How to set and get custom attributes in js

高洛峰
高洛峰Original
2016-12-09 15:22:341217browse

Js method to operate custom attributes:

var testEle = document.getElementByIdx_x("test")
 
testEle.setAttribute("test","aaa"); // 设置
testEle.getAttribute("test"); //获取
testEle.attributes["test"].nodeValue; // 获取

Jquery method to operate custom attributes:

$("#test").attr("test","aaa") // 设置
$("#test").removeAttr("test") // 删除
  
var testAttr = "ddd";
$('#test[test="'+ testAttr +'"]')


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn