lastChild বৈশিষ্ট্য

lastChild বৈশিষ্ট্যটি একটি উপাদানের শেষ নোড সংরক্ষণ করে। যদি উপাদানের কোন চাইল্ড নোড না থাকে - null ফেরত দেওয়া হয়।

সিনট্যাক্স

javascriptelement.lastChild;

উদাহরণ

চলুন একটি উপাদানের শেষ নোডের টেক্সটটি পাই:

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

console.log(text);

কোড 실행ের ফলাফল:

javascript'com'

আরও দেখুন

  • lastElementChild বৈশিষ্ট্য,
    যা শেষ উপাদান ধারণ করে
  • firstChild বৈশিষ্ট্য,
    যা প্রথম নোড ধারণ করে
  • childNodes বৈশিষ্ট্য,
    যা উপাদানের সমস্ত নোড ধারণ করে