Document.createAttribute() - Web APIs 编辑
The Document.createAttribute()
method creates a new attribute node, and returns it. The object created a node implementing the Attr
interface. The DOM does not enforce what sort of attributes can be added to a particular element in this manner.
The string given in parameter is converted to lowercase.
Syntax
attribute = document.createAttribute(name)
Parameters
name
is a string containing the name of the attribute.
Return value
A Attr
node.
Exceptions
INVALID_CHARACTER_ERR
if the parameter contains invalid characters for XML attribute.
Example
var node = document.getElementById("div1");
var a = document.createAttribute("my_attrib");
a.value = "newVal";
node.setAttributeNode(a);
console.log(node.getAttribute("my_attrib")); // "newVal"
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Document.createAttribute()' in that specification. | Living Standard | Precised behavior with uppercase characters |
Document Object Model (DOM) Level 3 Core Specification The definition of 'Document.createAttribute()' in that specification. | Obsolete | No change. |
Document Object Model (DOM) Level 2 Core Specification The definition of 'Document.createAttribute()' in that specification. | Obsolete | No change. |
Document Object Model (DOM) Level 1 Specification The definition of 'Document.createAttribute()' in that specification. | Obsolete | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论