JavaScript document.createAttribute() Method
You are Here:
JavaScript document.createAttribute() Method
The document.createAttribute()
method creates a new attribute node, and returns it.
Note: The DOM does not enforce what sort of attributes can be added to a particular element in this manner.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<img width="200" heigth="200">
<p>Click the button to add 'src' for the image</p>
<button onclick="myFunction()">Click Me</button>
<script>
var image = document.getElementsByTagName("img")[0];
function myFunction(){
var att = document.createAttribute("src");
att.value = "wikimass.png";
image.setAttributeNode(att);
}
</script>
</body>
</html>
Syntax
document.createAttribute(name)
Parameter Values
Value | Type | Explanation |
---|---|---|
name | Required | A string containing the name of the attribute. |
Return Values
Value | Explanation |
---|---|
Object | Returns a Attribute node. |
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.