#javascript #dom
Привет, как вывести дочерние узлы кроме первого и последнего? document.body.firstElementChild;Document Text
Other
Next
Last
Ответы
Ответ 1
if (document.body.children) { const children = document.body.children; for (var i = 1; i < children.length - 1; ++i) { console.log(children[i]) } }Ответ 2
Альтернативный вариант - использовать свойство .nextElementSibling const el = document.body.firstElementChild; while((el = el.nextElementSibling) && el.nextElementSibling){ console.log(el); }
Комментариев нет:
Отправить комментарий