एचटीएमएल डोम सेट एट्रिब्यूट नोड () विधि
तत्व वस्तुउदाहरण
<h1> तत्व का वर्ग विशेषता नोड सेट करें:
var h1 = document.getElementsByTagName("H1")[0]; // Get the first <h1> element in the document
var att = document.createAttribute("class"); // Create a "class" attribute
att.value = "democlass"; // Set the value of the class attribute
h1.setAttributeNode(att); // Add the class attribute to <h1>
विशेषता नोड सेट करने से पहले:
Hello World
विशेषता नोड सेट करने के बाद:
Hello World
नीचे और अधिक "इसे स्वयं आज़माएं" उदाहरण।
परिभाषा और उपयोग
setAttributeNode () विधि निर्दिष्ट विशेषता नोड को एक तत्व में जोड़ती है।
यदि निर्दिष्ट विशेषता पहले से मौजूद है, तो यह विधि इसे बदल देती है।
इस पद्धति का वापसी मूल्य एक Attr वस्तु है। अधिक जानकारी के लिए, HTML DOM एट्रीब्यूट ऑब्जेक्ट देखें ।
setAttribute() विधि भी देखें ।
युक्ति: किसी तत्व से विशेषता नोड को निकालने के लिए removeAttributeNode() विधि का उपयोग करें ।
ब्राउज़र समर्थन
Method | |||||
---|---|---|---|---|---|
setAttributeNode() | Yes | Yes | Yes | Yes | Yes |
वाक्य - विन्यास
element.setAttributeNode(attributenode)
पैरामीटर मान
Parameter | Type | Description |
---|---|---|
attributenode | Attr object | Required. The attribute node you want to add |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | एक Attr ऑब्जेक्ट, प्रतिस्थापित विशेषता नोड का प्रतिनिधित्व करता है, यदि कोई हो, अन्यथा शून्य |
---|---|
डोम संस्करण | कोर स्तर 1 तत्व वस्तु |
और ज्यादा उदाहरण
उदाहरण
<a> तत्व का href विशेषता नोड सेट करें:
var anchor = document.getElementById("myAnchor"); // Get the <a> element with id="myAnchor"
var att = document.createAttribute("href"); // Create a "href" attribute
att.value = "https://www.w3schools.com"; // Set the value of the href attribute
anchor.setAttributeNode(att); // Add the href attribute to <a>
विशेषता नोड सेट करने से पहले:
Go to w3schools.com
विशेषता नोड सेट करने के बाद:
संबंधित पृष्ठ
HTML ट्यूटोरियल: HTML विशेषताएँ
HTML DOM संदर्भ: HTML DOM विशेषता वस्तु
HTML DOM संदर्भ: setAttribute () विधि
HTML DOM संदर्भ: document.createAttribute () विधि
HTML DOM संदर्भ: विशेषता .value संपत्ति
HTML DOM संदर्भ: getAttributeNode () विधि
HTML DOM संदर्भ: removeAttributeNode () विधि
तत्व वस्तु