HTML DOM Document createAttribute() စက်မှု

အသုံးပြုနည်းဥပဒေ

code>createAttribute() စက်မှု ကို သုံးစွဲ၍ ဗီဇ ကို စက်ပေးပြီး ဗီဇ ကို Attr အပေါ်အထိပ်အဖြစ် ပြန်လည်ပေးသည်အခြားအဆို

အသုံးပြုပါ setAttribute() စက်မှု လမ်းကြောင်းများ

အခြေခံကြည့်ချင်ပါက

Element setAttribute() စက်မှု

Attribute value စက်မှု

Element setAttributeNode() စက်မှု

အမှတ်အသား

အကျိုးအခြေအား 1

// class အကျုပ် ဖွဲ့စည်းထားပါ:
const att = document.createAttribute("class");
// class အကျုပ် အမှတ်သား ကို သတ်မှတ်ထားပါ:
att.value = "democlass";
// ပထမဆုံး h1 အကျုပ်ကို class အကျုပ် ပါဝင်ထားသည့် အကျုပ်ကို ထပ်ပေါင်းထားပါ:
const h1 = document.getElementsByTagName("H1")[0];
h1.setAttributeNode(att);

ကိုယ်တိုင် ကျင်းသုံးကြည်း

အကျိုးအခြေအား 2

// style အကျုပ် ဖွဲ့စည်းထားပါ:
const att = document.createAttribute("style");
// style အကျုပ် အမှတ်သား ကို သတ်မှတ်ထားပါ:
att.value = "color:red";
// ပထမဆုံး h1 အကျုပ်ကို style အကျုပ် ပါဝင်ထားသည့် အကျုပ်ကို ထပ်ပေါင်းထားပါ:
const h1 = document.getElementsByTagName("h1")[0];
h1.setAttributeNode(att);

ကိုယ်တိုင် ကျင်းသုံးကြည်း

အကျိုးအခြေအား 3

href="www.codew3c.com" အကျုပ် ပါဝင်ထားသည့် anchor အကျုပ်ကို ထပ်ပေါင်းထားပါ:

// href အကျုပ် ဖွဲ့စည်းထားပါ:
const att = document.createAttribute("href");
// href အကျုပ် အမှတ်သား ကို သတ်မှတ်ထားပါ:
att.value = "https://www.codew3c.com";
// href အကျုပ် ပါဝင်ထားသည့် အကျုပ်ကို ထပ်ပေါင်းထားပါ:
element.setAttributeNode(att);

ကိုယ်တိုင် ကျင်းသုံးကြည်း

အပိုင်းအချက်

document.createAttribute(name)

ပါဝင်

ပါဝင် ဖော်ပြ
name လိုအပ်သည်။ ဖွဲ့စည်းထားရန် အကျုပ် အမှတ်သား

သတင်းပေး

အမျိုးအစား ဖော်ပြ
အကျုပ် အခြေခံ ဖြင့် ဖွဲ့စည်းထားသော အကျုပ် အသုံးစွဲသည်။ nadeName အကျုပ် အသုံးစွဲသည် name

ဖြိုးပေး

name အမှတ်သား မမှုန့်သော ကုက္ခဏာများ ပါဝင်ခဲ့ရှိသော် အဆိုပါ မီးရပ်ခြင်း စက္ခုကို ဖြိုးပေးသည်: INVALID_CHARACTER_ERR DOMException အမှား

ဘရီယာများ ထောက်ပံ့

document.createAttribute() သည် DOM Level 1 (1998) သုံးစွဲမှုဖြစ်သည်。

အားလုံးဘရီယာများတွင် ထောက်ပံ့သည်:

ခရိုးလ် အိုင်အို အင်ဂျင် ဖရူးဖရီ ဆာဖရီ အိုပရာ
ခရိုးလ် အိုင်အို အင်ဂျင် ဖရူးဖရီ ဆာဖရီ အိုပရာ
ထောက်ပံ့ 9-11 ထောက်ပံ့ ထောက်ပံ့ ထောက်ပံ့ ထောက်ပံ့