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

不言
Release: 2018-06-05 15:14:50
Original
3600 people have browsed it

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>
Copy after login

The js obtained Code:

Method 1: .innerText

var x1 = document.getElementById("testid").innerText; 

alert("x1="+x1);
Copy after login

Method 2: .innerHTML

##

var x2 = document.getElementById("testid").innerHTML; 

alert("x2="+x2);
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template