jQuery append()Method

jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Examples

Insert content at the end of all <p> elements:

$(document).ready(function(){ $("#btn1").click(function(){ $("p").append("<b>Inserted text</b>."); }); $("#btn2").click(function(){ $("ol").append("<li>Inserted item</li>"); }); });

Try it yourself »

Definition and Usage

The append() method inserts specified content at the end of the selected elements.

Tip:To insert content at the beginning of the selected elements, use theprepend()method.


Syntax

$(selector).append(content,function(index,html))

Parameter Description
content Required. Specifies the content to insert (can contain HTML tags).

Possible values:

  • HTML elements
  • jQuery objects
  • DOM elements
function(index,html) Optional. Specifies a function that returns the content to insert.
  • index- Returns the index position of the element in the set.
  • html- Returns the current HTML of the selected elements.


实例

More Examples

append() - Create content using HTML, jQuery, and DOM
Insert content using the append() method.

Use a function to append content
Use a function to insert content at the end of the selected elements.


jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Other Extensions