Get into span in javascript
Get into span in javascript
I want to get value of span with class "en-value" (48/100), placed in a
. Here's the html code: Can you help me?
Possible duplicate of Get value of Span Text
– SehaxX
Jun 29 at 11:02
4 Answers
4
use getElementsByClassName method
document.getElementsByClassName("en-value")[0].innerText
or querySelector which works in all modern browsers
document.querySelector("span.en-value").innerText
Thanks, second one works well. Love!
– Freese
Jun 29 at 11:05
add an id
to the span
and call getElementById
:
id
span
getElementById
<span class="en-value" id="myId">48/100</span>
var mypsan = document.getElementById("myId").innerHTML;
Here you go, a solution using pure js:
console.log(document.getElementByClass('en-value')[0].innerText);
Documentation: https://www.w3schools.com/jsref/met_document_getelementsbyclassname.asp
You can get it by giving the span
an id
attribute such as id=mySpan
and then
span
id
id=mySpan
var mySpanValue = document.querySelector("#mySpan").innerHTML;
Or if you do not want to add an id and want to select all elements of that class
, then
class
var myArrOfEnVal = document.querySelectorAll(".en-value");
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
this is easily googable
– ThisGuyHasTwoThumbs
Jun 29 at 11:01