HTML () method
This method is similar to the innerHTML property in JavaScript, and can be used to read or set HTML content in an element. To get the contents of an element, you can do this:
Copy Code code as follows:
var p_html = $ ("P"). html (); Get the HTML code for the P element
You can also use this method if you need to set the HTML code for an element, but you need to pass it a parameter. For example, to set the HTML code for the P element, you can use the following code:
Copy Code code as follows:
Set the HTML code for the P element
$ ("P"). HTML ("Welcome to the concise modern Magic Library ~ ~");
Note: the HTML () method can be used for XHTML documents, but not for XML documents.
text () method
This method is similar to the InnerText property in JavaScript, which can be used to read or not place textual content in an element. Continue using the HTML code above, and use the text () method to manipulate the P element:
Copy Code code as follows:
var P_text = $ ("P"). text (); Get the text content of the P element
As with the HTML () method, if you need to set the text content for an element, you also need to pass a parameter. For example, to set the text content for the P element, the code is as follows:
Copy Code code as follows:
Set the text content of the P element
$ ("P"). Text ("You are welcome to visit the Concise modern Magic Library ~ ~");
Be aware of the following two points:
The innertext attribute in JavaScript does not run in Firefox, and jquery's text () method supports all browsers.
The text () method is valid for both the HTML document and the XML document.
When displaying the buddy list, set the <p></p> element in the display buddy name: <p id= "P${friend.friendid}" ></p>, so that the JS file can be dynamically obtained <p> </p> ID of the element and successfully assigned $ ("#p" +userid) by the text () method. Text (name);