The following editor will bring you a js method to obtain the value of the span tag of html (super simple). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.
The code in HTML is:
<span id="testid">aaaa</span>
The js obtained Code:
Method 1: .innerText
var x1 = document.getElementById("testid").innerText; alert("x1="+x1);
Method 2: .innerHTML
##
var x2 = document.getElementById("testid").innerHTML; alert("x2="+x2);
##Related recommendations:
js method to get the actual width and height of Html elementsThe above is the detailed content of js method to get the value of html span tag (super simple). For more information, please follow other related articles on the PHP Chinese website!