Append (Content): Method inserts the specified content at the end of the selected element (still inside), and many friends feel that append is similar to HTML, and that other append in English sense are added on the original basis, while the HTML replaces all current content.
Definitions and usage
The Append () method inserts the specified content at the end of the selected element (still inside).
$ (selector). Append (content)
Use functions to attach content
Inserts the content at the end of the specified element using the function.
Grammar
$ (selector). Append (function (index,html))
Instance code:
<script src= "/jquery.min.js" type= "Text/javascript" ></script>
<style>
imgfocus{border : 1px solid #eee;}
</style>
<p> </p>
<script type= "Text/javascript" >
var showimg = "<div class=" Imgfocus ' >123456</div> ';
$ ("P"). Append (showimg);
</script>
The HTML () method returns or sets the content of the selected element (inner HTML).
If the method does not set a parameter, the current contents of the selected element are returned.
return element content
When you use this method to return a value, it returns the contents of the first matching element.
Grammar
$ (selector). HTML ()
Set the contents of all P elements:
$ (". Btn1"). Click (function () {
$ ("P"). html ("Hello <b>world</b>!");
});
Empty the specified element
$ ("a[href$= ' logout.asp ']"). Click (Function (event) {
event.preventdefault ();
$.get ("/xxlr/logout.asp", "", Function (data, textstatus) {
if (data = 1) {//Indicates cancellation success
$ (' #message '). HTML ("");
$ ("#userlogin >div"). Show ();
else {
$ (' #message '). Append ("<p><strong> logoff failed, please retry!</strong></p>");});
The following is a netizen's supplement:
Of course not, append is append, HTML is completely replaced
Like <p id= "1" ><p>123</p></p>
$ ("#1"). HTML ("<span>456</span>");
The result is: <p id= "1" ><span>456</span></p>
$ ("#1"). Append ("<span></span>");
The result is: <p id= "1" ><p>123</p><span>456</span></p>