I am trying to gather these HTML objects through getElementsByClassName
, and push them into a JavaScript array and then I want to create a JavaScript alert
to display these names. I’ve been trying this for hours. Am I doing something wrong?
var names = []
var elm = document.getElementsByClassName('name');
names.push(elm);
var arr = names.join();
alert(arr)
<h2>
List of People:
</h2>
<ul class='people'>
<li class='name'>
Clara
</li>
<li class='name'>
James
</li>
<li class='name'>
Sara
</li>
</ul>