0

How it works? 😅😅

Мне не понятно как работает удаление параграфов... Измените индексы в child [] I don't understand how paragraph deletion works... Change indices in child [] https://code.sololearn.com/WKA5e2QRiDFe/?ref=app

22nd Jun 2021, 7:20 PM
BOHDAN LUKIANCHENKO
BOHDAN LUKIANCHENKO - avatar
2 Antworten
+ 4
BOHDAN LUKIANCHENKO childNodes returns collection of child node. If you put whitespace after parent element then that would be consider as text and this text will be a child node. So actually you have whitespace as a child node at 0th position. Try to remove whitespace after opening div then you will get how it is working.
22nd Jun 2021, 7:47 PM
A͢J
A͢J - avatar
0
to get only list of html elements (not the text nodes), you could use 'children' property instead of 'childNodes'... as the returned array-like is dynamic, removing one element will remove it also from the children list ^^ so, you must remove first higher indices to lower ones: window.onload = function() { var parent = document.getElementById("demo"); var child = parent.children; parent.removeChild(child[1]); parent.removeChild(child[0]); }; alternatively, you could use twice the index 0 ;)
23rd Jun 2021, 3:18 AM
visph
visph - avatar