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

Asked

Viewed 148 times

-1

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

That is the code.

I need to take the "0" result and put it on 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 separate span class.

You can take all the Span Class "odemeter-value" and play it all for one label?

Thank you for your attention.

  • You will read this code from a Webbrowser?

  • The webbrowser needs to be present yes, but is in enable=off

  • In case a button would have to use Webbrowser1.Getelementbyid take all span/class equal and give me the result in a textbox or label.

1 answer

0

If I understand correctly, it 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.