HTML DOM Document 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);
အောက်တွင် နောက်ထပ် ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
method သည် createAttribute()
attribute တစ်ခုဖန်တီးပြီး attribute ကို Attr object တစ်ခုအဖြစ် ပြန်ပေးသည်။
အစားထိုး-
၎င်းသည် element .setAttribute() method ကိုအသုံးပြုရန်ပိုမိုလွယ်ကူသည်။
ကိုလည်းကြည့်ပါ-
Element setAttribute() နည်းလမ်း
အထားအသို
document.createAttribute(name)
ကန့်သတ်ချက်များ
Parameter | Description |
name | Required. The name of the attribute to create. |
တန်ဖိုးကို ပြန်ပေးသည်။
ရိုက်ပါ။ | ဖော်ပြချက် |
Node | ဖန်တီးထားသော attribute node |
နောက်ထပ် ဥပမာများ
a 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);
Browser ပံ့ပိုးမှု
document.createAttribute()
DOM Level 1 (1998) အင်္ဂါရပ်တစ်ခုဖြစ်သည်။
ဘရောက်ဆာအားလုံးတွင် ၎င်းကို အပြည့်အဝထောက်ခံသည်-
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |