What is the difference between text(), html() and val() in jQuery?
<div id="d">Hello <b>world</b></div>
<input id="i" value="Anita">
console.log($('#d').text());
console.log($('#d').html());
console.log($('#i').val());
Console output
Hello world
Hello <b>world</b>
Anita
Use .text() for text from users, because .html() can run HTML and scripts. See Get Content.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |