HTML DOM setAttributeNode() နည်းလမ်း
❮ Element Objectဥပမာ
<h1> ဒြပ်စင်တစ်ခု၏ class attribute node ကို သတ်မှတ်ပါ-
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>
attribute node ကိုမသတ်မှတ်မီ-
Hello World
attribute node ကို သတ်မှတ်ပြီးနောက်၊
Hello World
အောက်တွင် နောက်ထပ် "စမ်းသုံးကြည့်ပါ" ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
setAttributeNode() နည်းလမ်းသည် သတ်မှတ်ထားသော attribute node အား ဒြပ်စင်တစ်ခုသို့ ပေါင်းထည့်သည်။
သတ်မှတ်ထားသော အရည်အချင်းရှိပြီးသားဖြစ်ပါက၊ ဤနည်းလမ်းသည် ၎င်းကို အစားထိုးသည်။
ဤနည်းလမ်း၏ return value သည် Attr object တစ်ခုဖြစ်သည်။ ပိုမိုသိရှိလိုပါက၊ HTML DOM Attribute Object ကို ကြည့်ပါ ။
setAttribute() နည်းလမ်း ကိုလည်း ကြည့်ပါ ။
အကြံပြုချက်- ဒြပ်စင်တစ်ခုမှ attribute node ကိုဖယ်ရှားရန် removeAttributeNode() နည်းလမ်းကို အသုံးပြု ပါ။
Browser ပံ့ပိုးမှု
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 object တစ်ခု၊ အစားထိုးထားသော attribute node ကို ကိုယ်စားပြုသည် ၊ သို့မဟုတ်ပါက null |
---|---|
DOM ဗားရှင်း | Core Level 1 Element Object |
နောက်ထပ် ဥပမာများ
ဥပမာ
<a> ဒြပ်စင်တစ်ခု၏ href attribute node ကို သတ်မှတ်ပါ-
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>
attribute node ကိုမသတ်မှတ်မီ-
Go to w3schools.com
attribute node ကို သတ်မှတ်ပြီးနောက်၊
ဆက်စပ်စာမျက်နှာများ
HTML သင်ခန်းစာ- HTML အရည်အချင်းများ
HTML DOM ရည်ညွှန်း- HTML DOM ရည်ညွှန်းချက် အရာဝတ္တု
HTML DOM ရည်ညွှန်းချက်- setAttribute() နည်းလမ်း
HTML DOM အကိုးအကား- document.createAttribute() နည်းလမ်း
HTML DOM ရည်ညွှန်းချက်- attribute .value Property
HTML DOM အကိုးအကား- getAttributeNode() နည်းလမ်း
HTML DOM အကိုးအကား- removeAttributeNode() နည်းလမ်း
❮ Element Object