getAttribute နည်းလမ်း

getAttribute နည်းလမ်းသည် တဂ်တစ်ခုမှ သတ်မှတ်ထားသော Attribute ၏ တန်ဖိုးကို ဖတ်ရှုသည်။

ဝါကျဖွဲ့ပုံ

javascriptelement.getAttribute(attribute အမည်);

ဥပမာ

အောက်ပါ element ၏ value Attribute ပါ အကြောင်းအရာကို ထုတ်ပြကြပါစို့:

html<input id="elem" value="abcde">
javascriptlet elem = document.querySelector('#elem');
let value = elem.getAttribute('value');

console.log(value);

ကုဒ်ကို လုပ်ဆောင်ခြင်း၏ ရလဒ်:

javascript'abcde'

ဒါတွေလည်း ကြည့်ပါ

  • setAttribute နည်းလမ်း,
    သည် Attribute များကို ရေးသားသည့် နည်းလမ်း
  • removeAttribute နည်းလမ်း,
    သည် Attribute များကို ဖယ်ရှားသည့် နည်းလမ်း
  • hasAttribute နည်းလမ်း,
    သည် Attribute များကို စစ်ဆေးသည့် နည်းလမ်း