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:
var p_html = $("p").html(); //Get the HTML code for the p element
If you need to set the HTML code for an element, you can also use this method, but you need to pass a parameter to it. For example, to set the HTML code of the p element, you can use the following code:
//Set the HTML code of 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, and can be used to read or dispose of text content in an element. Continue to use the above HTML code and use the text() method to operate on the p element:
var p_text = $("p").text(); //Get the text content of the p element
Like the html() method, if you need to set text content for a certain element, you also need to pass a parameter. For example, set text content for p elements, the code is as follows:
// Set the text content of the p element
$("p").text("Welcome to the Concise Modern Magic Library~~");
The following two points should be noted:
The innerText property in JavaScript cannot run under Firefox browser, and jQuery's text() method supports all browsers.
The text() method is valid for both HTML documents and XML documents.
When displaying the friend list, set: <p></p> element that displays the friend's name, so that the js file can dynamically obtain the id of the <p></p> element and successfully assign $("#p"+userId).text(name);
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:
Copy the codeThe code is as follows:
var p_html = $("p").html(); //Get the HTML code for the p element
If you need to set the HTML code for an element, you can also use this method, but you need to pass a parameter to it. For example, to set the HTML code of the p element, you can use the following code:
Copy the codeThe code is as follows:
//Set the HTML code of 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, and can be used to read or dispose of text content in an element. Continue to use the above HTML code and use the text() method to operate on the p element:
Copy the codeThe code is as follows:
var p_text = $("p").text(); //Get the text content of the p element
Like the html() method, if you need to set text content for a certain element, you also need to pass a parameter. For example, set text content for p elements, the code is as follows:
Copy the codeThe code is as follows:
// Set the text content of the p element
$("p").text("Welcome to the Concise Modern Magic Library~~");
The following two points should be noted:
The innerText property in JavaScript cannot run under Firefox browser, and jQuery's text() method supports all browsers.
The text() method is valid for both HTML documents and XML documents.
When displaying the friend list, set: <p></p> element that displays the friend's name, so that the js file can dynamically obtain the id of the <p></p> element and successfully assign $("#p"+userId).text(name);