HTML DOM ထည့်သွင်းပါ၀င်သော ကပ်လျက်HTML () နည်းလမ်း
ဥပမာ
ခေါင်းစီးဒြပ်စင်ပြီးနောက် <p> ဒြပ်စင်အသစ်ကို ထည့်သွင်းပါ-
var h = document.getElementById("myH2");
h.insertAdjacentHTML("afterend",
"<p>My new paragraph</p>");
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် insertAdjacentHTML()
သတ်မှတ်ထားသော အနေအထားတစ်ခုတွင် စာသားကို HTML အဖြစ် ထည့်သွင်းသည်။
တရားဝင်ရာထူးတန်ဖိုးများမှာ-
"afterbegin"
"afterend"
"beforbegin"
"beforeend"
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် နည်းလမ်းကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးသည်။
Method | |||||
---|---|---|---|---|---|
insertAdjacentHTML() | 1 | 4 | 8 | 4 | 7 |
အထားအသို
node.insertAdjacentHTML(position, text)
ကန့်သတ်တန်ဖိုးများ
Parameter | Type | Description |
---|---|---|
position | String | Required. A position relative to the element. Legal values: "afterbegin" - After the beginning of the element (as the first child) "afterend" - After the element "beforebegin" - Before the element "beforeend" - Before the end of the element (as the last child) |
text | String | The text you want to insert |
နောက်ထပ် ဥပမာများ
ဥပမာ
"afterbegin" တန်ဖိုးကို အသုံးပြုခြင်း-
h.insertAdjacentHTML("afterbegin", "<span style='color:red'>My span</span>");
ဥပမာ
"bebegin" တန်ဖိုးကို အသုံးပြုခြင်း-
h.insertAdjacentHTML("beforebegin", "<span style='color:red'>My span</span>");
ဥပမာ
"ရှေ့" တန်ဖိုးကို အသုံးပြုခြင်း-
h.insertAdjacentHTML("beforeend", "<span style='color:red'>My span</span>");