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

How to set and get custom attributes in js

高洛峰
Release: 2016-12-09 15:22:34
Original
1170 people have browsed it

Js method to operate custom attributes:

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

Jquery method to operate custom attributes:

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


Related labels:
js
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template