شرح صفوف ومحتوى الفقرة
في بنية شجرة DOM القياسية، لا يُخزن النص المكتوب داخل <h2>Welcome</h2> كسمة على الوسم نفسه، بل يعيش داخل عقدة نصية ابنة تمثل heading.firstChild!
وتتيح قراءة أو تعديل heading.firstChild.nodeValue تحديث النص الافتتاحي وحده دون مسح أي أيقونة شقيقة موضوعة بجانبه في نهاية العنوان (بخلاف إسناد heading.textContent الذي يستبدل كافة الأبناء).
JavaScript
const titleEl = document.getElementById('card-heading');
const btn = document.getElementById('rename-btn');
btn.addEventListener('click', function () {
if (titleEl.firstChild && titleEl.firstChild.nodeType === 3) {
titleEl.firstChild.nodeValue = 'Server Online ';
}
});