एचटीएमएल डोम दस्तावेज़ createAttribute ()
उदाहरण
// Create a class attribute:
const att = document.createAttribute("class");
// Set the value of the class attribute:
att.value = "democlass";
// Add the class attribute to the first h1:
const h1 = document.getElementsByTagName("H1")[0];
h1.setAttributeNode(att);
// Create a style attribute:
const att = document.createAttribute("style");
// Set the value of the style attribute:
att.value = "color:red";
// Add the style attribute to the first h1:
const h1 = document.getElementsByTagName("h1")[0];
h1.setAttributeNode(att);
नीचे और अधिक उदाहरण।
परिभाषा और उपयोग
विधि एक विशेषता बनाती है और createAttribute()
विशेषता को Attr ऑब्जेक्ट के रूप में लौटाती है।
वाक्य - विन्यास
document.createAttribute(name)
मापदंडों
Parameter | Description |
name | Required. The name of the attribute to create. |
प्रतिलाभ की मात्रा
प्रकार | विवरण |
नोड | निर्मित विशेषता node. |
और ज्यादा उदाहरण
एक href="www.w3schools.com" एक एंकर तत्व विशेषता जोड़ें:
// Create a href attribute:
const att = document.createAttribute("href");
// Set the value of the href attribute:
att.value = "https://www.w3schools.com";
// Add the href attribute to an element:
element.setAttributeNode(att);
ब्राउज़र समर्थन
document.createAttribute()
एक डोम लेवल 1 (1998) फीचर है।
यह सभी ब्राउज़रों में पूरी तरह से समर्थित है:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |