Someone asked me in the early days what is the difference between html () and text ?? I didn't know at first, but now I can see the jquery api.
Let's take a look at the function description on jquery api:
Html (): gets the html content of the First Matching Element. This function cannot be used in XML documents. But it can be used in XHTML documents.
Text (): gets the text that is composed of all the text content contained in the matching element. This method is effective for both HTML and XML documents.
Pay attention to the keywords marked above, and you will see them carefully. The following is a simple example:
<P> longge blog </p>
<P> test section </p>
Alert ($ ("p"). text ());
Alert(%(%p%%%.html ());
If you understand the above Code, it is easy to know the running result !!
Alert ($ ("p"). text (); // result
Alert ($ ("p" ).html (); // Similarly, the returned result is "longge blog", which gets the html code in the middle of the First Matching Element