-4

I am using inside my page <span> tag like this

<span class="class_name">1500</span>

and I have a javascript code who change "1500" to 15%

my question is how to read the number inside the span and print the new number
I want an example code.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Donjwan
  • 35
  • 1
  • 8
  • https://www.w3.org/community/webed/wiki/Traversing_the_DOM – Quentin Sep 22 '16 at 13:39
  • 1
    var number = parseInt(document.querySelector(".class_name").innerHTML); –  Sep 22 '16 at 13:39
  • Possible duplicate of [Change an element's class with JavaScript](http://stackoverflow.com/questions/195951/change-an-elements-class-with-javascript) – Dsenese1 Sep 22 '16 at 13:40
  • You say you have code that changes the number, and you're asking us for example code that basically does the same thing? –  Sep 22 '16 at 13:42
  • my code are function numberchange(number) { return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); i want it to read from the span and change the number – Donjwan Sep 22 '16 at 13:43
  • 1
    Possible duplicate of [Difference between innerText and innerHTML in javascript](http://stackoverflow.com/questions/19030742/difference-between-innertext-and-innerhtml-in-javascript) – Paul Sweatte Sep 22 '16 at 15:55

2 Answers2

0

you can try
var number = parseInt(document.querySelector('span.class_name').innerHTML);

pratyush jha
  • 143
  • 1
  • 2
  • 7
0

try this

<span id="thisspan" class="whateverclass">1500</span>
<div id="thevalueis"></div>
<script>
   document.getElementById("thevalueis").innerHTML=document.getElementById("thisspan").innerHTML;
</script> 

I hope i got your question right. :)

Sky
  • 39
  • 3