Home > Web Front-end > JS Tutorial > body text

The difference between text(), html() and val() in js

高洛峰
Release: 2016-10-09 13:51:19
Original
1220 people have browsed it

The difference between text(), html() and val() in js

text(), html() and val() are used to store and get values ​​of html elements, but they each have their own differences Features: text() is used to access the text content of html elements. html() can be used not only to access the text content of html elements, but also to access html content. val() is used to access the content of the input element.

一. text()

var text = $("div").text();

console.log(text);

text

console:text

 

二.html( )

text

var str = $("div").html();

console.log(str);

console:

text

three. val()

var str = $("input").val();

console.log(str);

console:text

Similarities and differences:

text() and html() can both be used for element text Access, but html() can be used not only for accessing element text, but also for accessing element nodes.

val() is different from text() and html(), val() is used to access the content of the input node.


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