jquery's text(), html() and val() usage

The text() method method sets or returns the text content (innerText) of the selected element:

The html() method returns or sets the content (innerHTML) of the selected element, including tags:



1234



$("#data").text(); //Return 1234, the tags in data will be ignored, only the content will be returned, similar to innerText in js
$("#data").text("Hello"); // img and p inside data will be deleted, and the content will be replaced with "hello"      
$("#data").html(); //return string "

1234

"
$("#data").html("Hello"); //The img and p inside the data will be deleted, and the content will be replaced with "Hello"

The val() method returns or sets the value of the selected element

$("input").val(); //Return the value of the input "1133445fddsgfsgfadfa"
$("input").val() = "Send it, so annoying"; //Set the value of the value

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324925348&siteId=291194637