How to get text from a Span with Class [VB.NET]

-1
<span class="odometer-value">0</span>

This is the code.

I need to get the result "0" and put it in a Label.

But sometimes you can have ex: 10 (2 numbers) and the code will be:

<span class="odometer-value">1</span>
<span class="odometer-value">0</span>

That is 2 span span separated.

How to get all Span Class "odemeter-value" and play everything for a Label?

Thanks for your attention.

    
asked by anonymous 30.10.2018 / 18:22

1 answer

0

If I understand correctly, this solves your problem.

function teste(){

    var textSpan = document.getElementsByClassName('odometer-value')
    var textLabel = document.getElementById('mylabel').textContent;

    for (let index = 0; index < textSpan.length; index++) {
        const element = textSpan[index];
        textLabel = textLabel + element.textContent;
    }
    document.getElementById('mylabel').innerHTML = textLabel;
    
}
window.onload = teste();
<span class="odometer-value">3</span>
    <span class="odometer-value">1</span>
    <span class="odometer-value">0</span>
    <br>
    <label id="mylabel">minha label: </label>
    
16.11.2018 / 18:29