Is it possible to get the value of a div?

2

If the div valor0 has a value, how can I get this value in a variable to sum it up for example ??

In this example we have the valor0 div with the value 1, how do I send it to the test variable?

var teste = document.getElementById("valor0").value;
console.log(teste);
<html>
	<div id="valor0"> 1 </div>
</html>
    
asked by anonymous 05.10.2017 / 13:25

1 answer

7

You can fetch .textContent and then parse to convert to Number.

var text = document.getElementById("valor0").textContent;
var numero = Number(text);
console.log(typeof text, text, '||', typeof numero, numero);
<div id="valor0"> 1 </div>
    
05.10.2017 / 13:27