The jquery append () method differs from the HTML () method usage

Source: Internet
Author: User

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>");    }    


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.