How do you get text wrapped in a span block in pure JavaScript? id block can not hang. only the name of the class is known.

I tried this:

var price; price = document.getElementsByClassName('name2'); alert(price.innerHTML); 
 <span class="name2">iii</span> <span class="name2">еще текст</span> 

does not exceed. I would be grateful for the help!

    1 answer 1

    Referring to document.getElementsByClassName('name2') , you refer to an array of elements with the class name2 . To refer to the first of them, you must specify its sequence number in the array.

     var price = document.getElementsByClassName('name2'); alert(price[0].innerHTML); 
     <span class="name2">iii</span>