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);
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.