In jquery. HTML () is used for reading and modifying elements of the HTML tag,. Text () to read or modify the plain text content of the element,. Val () is used to read or modify the value of the form element.
1.HTML
HTML (): Gets the HTML content of the first matching element. This function cannot be used with XML documents. But can be used in XHTML documents
HTML (val): Sets the HTML content of each matching element. This function cannot be used with XML documents. But it can be used in XHTML documents.
2.TEXT
Text (): Gets the contents of all matching elements. General with ID difference
The result is text that is combined with the text content contained by all matching elements. This method is valid for both HTML and XML documents.
Text (val): Sets the textual content of all matching elements
Similar to HTML (), but encodes HTML (replaces "<" and ">" with the corresponding HTML entity).
3.VAL
Val (): Gets the current value of the first matching element. Typically used to take the value of input.
Val (val): Sets the value of each matching element.
The above content is copied in the jquery Help document, and no more talking nonsense. Here are some of your own exercises, the code is as follows:
I found another different place in HTML and text when I was doing the exercises.
HTML () to the content of the element, you can select the element below the format is also taken.
such as: <div id= "Divshow" ><b><i>write less do more</i></b></div>
If we use var strHTML = $("#divShow").html();
them,
The result is: <b><i>write less do more</i></b>
If we use var strHTML2 = $ ("#divShow b I"). html ();
The result is write less does more
And the text doesn't have the first case,
If we var StrText = $ ("#divShow"). Text ();
The result is write less does more
If we var StrText = $ ("#divShow"). Val ();
The result is ""
The HTML (), text (), Val () difference in jquery