Skip to content
Advertisement

Check how many there are in a with javascript

Following my code:

HTML:

JavaScript

JS:

JavaScript

Why the in the console there are the number 0 instead of 2?

Advertisement

Answer

Give – document.getElementById("ul_o").getElementsByTagName("li").length

To have a wider answer that ensures the dom is ready for being accessed and updated by JS, we can make use of the onreadystatechange event something like in html5 –

JavaScript

Fiddle

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement