How to get this value inside the div

2

The div is:

<div class="table_box br_0_0_5_5 user_points" style="border-top:none;">4,660</div>

Code to paste this div:

 document.getElementsByClassName("table_box br_0_0_5_5 user_points")[0]

How can I get the value "4,660" and put in an alert? I tried several ways but I did not succeed.

    
asked by anonymous 10.05.2018 / 03:29

1 answer

0

You can use .textContent (captures text within the element):

var texto = document.getElementsByClassName("table_box br_0_0_5_5 user_points")[0].textContent;
alert(texto);
<div class="table_box br_0_0_5_5 user_points" style="border-top:none;">4,660</div>

But you also do not need to include all the classes in the method, with only one already enough (if it is the first one on the page):

var texto = document.getElementsByClassName("br_0_0_5_5")[0].textContent;
alert(texto);
<div class="table_box br_0_0_5_5 user_points" style="border-top:none;">4,660</div>
    
10.05.2018 / 03:33