Append (content): The method inserts the specified content at the end of the selected element (still inside), and many friends feel that the append is almost the same as HTML, and that the other append is added on the original basis in the English sense, while the HTML replaces all current content.
Definition and usage
The Append () method inserts the specified content at the end of the selected element (still inside).
$ (selector). Append (content)
Using functions to attach content
Uses a function to insert content at the end of a specified element.
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 contents 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 ()
To set the contents of all P elements:
$ (". Btn1"). Click (function () { $ ("P"). html ("Hello <b>world</b>!");});
clears the specified element
$ ("a[href$= ' logout.asp ']"). Click (Function (event) { event.preventdefault (); $.get ("/xxlr/logout.asp", "", Function (data, textstatus) { if (data = = 1) { //indicates logoff succeeded $ (' #message '). HTML ("" ); $ ("#userlogin >div"). Show (); } else { $ (' #message '). Append ("<p><strong> logoff failed, please retry!</strong></p>"); }