شرح صفوف ومحتوى الفقرة
عندما يُكتب عنصر <label> في سطر ويليه حقل <input> في السطر التالي، تقف الخاصية التقليدية input.previousSibling عند عقدة المسافة النصية الفاصلة، بينما تصل input.previousElementSibling مباشرةً إلى وسم <label> بثبات تام في كل مرة.
JavaScript
const field = document.getElementById('api-token');
const readBtn = document.getElementById('read-adj');
const out = document.getElementById('adj-out');
readBtn.addEventListener('click', function () {
const prevInput = readBtn.previousElementSibling;
const prevLabel = field.previousElementSibling;
out.textContent =
prevLabel.textContent + ' -> ' + prevInput.value;
});