lastChild property

lastChild property သည် element ၏ နောက်ဆုံး node ကို သိမ်းဆည်းထားသည်။ အကယ်၍ element တွင် child elements များ မရှိပါက null ကို ပြန်ပေးသည်။

Syntax

javascriptelement.lastChild;

ဥပမာ

Element ၏ နောက်ဆုံး node ၏ text ကို ရယူကြည့်ရအောင်။

html<div id="parent">text<p>parag</p><!--com--></div>
javascriptlet parent = document.querySelector('#parent');
let text = parent.lastChild.textContent;

console.log(text);

Code run ပြီးနောက်ရရှိသော ရလဒ်။

javascript'com'

ဆက်လက်ဖတ်ရှုရန်

  • lastElementChild property,
    သည် နောက်ဆုံး element ကို ထည့်သွင်းထားသည်
  • firstChild property,
    သည် ပထမဆုံး node ကို ထည့်သွင်းထားသည်
  • childNodes property,
    သည် element ၏ node အားလုံးကို ထည့်သွင်းထားသည်