Home >Web Front-end >HTML Tutorial >js method to get the value of html span tag (super simple)

js method to get the value of html span tag (super simple)

不言
不言Original
2018-06-05 15:14:503660browse

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 elements


The 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn