S
S
Stacy None2018-02-19 10:36:46
JavaScript
Stacy None, 2018-02-19 10:36:46

How to display the received information with a div in javascript?

I counted in Javascript the number of "li" elements in a block with a certain "id" like so:

document.write(document.getElementById('111').childNodes.length);

Question: How to display the result (number) for example with the " " tag ? <div id='result'></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2018-02-19
@Stacy11

var numberOfLis = document.getElementById('111').childNodes.length; //сохраняем кол-во дочерних элементов в переенную numberOfLis 
document.getElementById('result').innerText(numberOfLis); //выводим значение переменной как текст в блоке с id result

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question