Как такие возможно js?

D
На сайте с 28.06.2008
Offline
1114
740

Код

if (screen.width < 990) {
  let child = document.getElementsByTagName('ul');
console.log(child);
console.log(child[0]);
child.style.display = 'block';
}

Вывод


Первый консоль лог показывает коллекцию, а второй ничего. Как так?

I
На сайте с 06.08.2022
Offline
22
#1
document.getElementsByTagName('ul')[0].style.display ?
I
На сайте с 01.05.2015
Offline
72
#2
По моему, в документации все есть https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection/item
HTMLCollection.item() - Web APIs | MDN
HTMLCollection.item() - Web APIs | MDN
  • 2022.06.24
  • developer.mozilla.org
The method returns the node located at the specified offset into the collection. Note: Because the contents of an are live, changes to the underlying DOM can and will cause the position of individual nodes in the collection to change, so the index value will not necessarily remain constant for a given node.
D
На сайте с 28.06.2008
Offline
1114
#3
Перенес свой скрипт в самый низ кода и все заработало.

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий