HTML DOM Element getAttribute()
❮ Element Objectဥပမာ
ဒြပ်စင်တစ်ခု၏ class attribute ၏တန်ဖိုးကို ရယူပါ-
let value = document.getElementById("myId").getAttribute("class");
အောက်တွင် နောက်ထပ် ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
getAttribute()
method သည် element တစ်ခု၏ attribute ၏တန်ဖိုးကို ပြန်ပေးသည် ။
ကျူတိုရီရယ်
ကိုလည်းကြည့်ပါ-
အထားအသို
element.getAttribute(attributename)
ကန့်သတ်တန်ဖိုးများ
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute you want to get the value from |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | သတ်မှတ်ထားသော attribute ၏တန်ဖိုးကိုကိုယ်စားပြုသော စာကြောင်းတစ်ခု။ မှတ်ချက် ။ _ _ |
---|---|
DOM ဗားရှင်း | Core Level 1 Element Object |
နောက်ထပ် ဥပမာများ
ဥပမာ
<a> ဒြပ်စင်တစ်ခု၏ ပစ်မှတ် attribute ၏တန်ဖိုးကို ရယူပါ-
var x = document.getElementById("myAnchor").getAttribute("target");
ဥပမာ
<button> ဒြပ်စင်တစ်ခု၏ onclick event attribute ၏တန်ဖိုးကို ရယူပါ-
var x = document.getElementById("myBtn").getAttribute("onclick");
Browser ပံ့ပိုးမှု
element.getAttribute
DOM Level 1 (1998) အင်္ဂါရပ်တစ်ခုဖြစ်သည်။
ဘရောက်ဆာအားလုံးတွင် ၎င်းကို အပြည့်အဝထောက်ခံသည်-
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |
❮ Element Object