I wanted to know how I can get the number of elements in JavaScript
which function should I use I was looking for but I did not find it.
Code example:
var parentDOM = document.getElementById("parent-id");
var test=parentDOM.getElementsByClassName("test");//test is not target element
console.log(test);//HTMLCollection[1]
var testTarget=parentDOM.getElementsByClassName("test")[0];//here , this element is target
console.log(testTarget);//<p class="test">hello word2</p>
<div id="parent-id">
<p class="prueba">hello word1</p>
<p class="test">hello word2</p>
<p class="test">hello word3</p>
<p class="test">hello word4</p>
</div>
How can I know the number of elements in class test
. and if not, it is possible to return it as a list and separate it each one. How could it be?