HTML DOM createAttribute () method
Examples
Create a class attribute, attribute value "democlass", and clas attribute to the H1 element:
var att=document.createAttribute("class");
att.value="democlass";
document.getElementsByTagName("H1")[0].setAttributeNode(att);
att.value="democlass";
document.getElementsByTagName("H1")[0].setAttributeNode(att);
Element attribute before adding:
Hello World
Add property elements:
Hello World
try it"
Definition and Usage
createAttribute () method is used to create a property with the specified name, and returns a Attr object properties.
Browser Support
All major browsers support createAttribute () method
grammar
document.createAttribute(attributename)
parameter
参数 | 类型 | 描述 |
---|---|---|
attributename | Attr object | 必须。要创建的属性名称。 |
return value
类型 | 描述 |
---|---|
节点对象 | 创建的属性 |
technical details
DOM version | Core Level 1 Document Object |
---|