hasAttribute နည်းလမ်း
hasAttribute နည်းလမ်းသည် element တစ်ခုတွင်
သတ်မှတ်ထားသော attribute တစ်ခုရှိမရှိ စစ်ဆေးပေးသည်။ attribute
ရှိပါက true ထွက်ပေါ်လာမည်၊ မရှိပါက false ထွက်ပေါ်လာမည်။
ဝါကျဖွဲ့ပုံ
javascriptelement.hasAttribute(attribute နာမည်);
နမူနာ
value attribute
element တစ်ခုတွင် ရှိမရှိ စစ်ဆေးကြည့်ရအောင်။
html<input id="elem" value="abcde">javascriptlet elem = document.querySelector('#elem');
console.log(elem.hasAttribute('value'));
ကုဒ်ကို လုပ်ဆောင်ပြီးနောက် ရလဒ်။
javascripttrue
နမူနာ
ယခု value attribute မရှိတော့ပါ။
html<input id="elem">javascriptlet elem = document.querySelector('#elem');
console.log(elem.hasAttribute('value'));
ကုဒ်ကို လုပ်ဆောင်ပြီးနောက် ရလဒ်။
javascriptfalse
ဆက်လက်လေ့လာရန်
-
getAttributeနည်းလမ်း,
သည် attribute များကို ရယူပေးသည်။ -
setAttributeနည်းလမ်း,
သည် attribute များကို ရေးသားသွင်းလိုက်သည်။ -
removeAttributeနည်းလမ်း,
သည် attribute များကို ဖျက်ပစ်သည်။