jQuery append() Metoda

❮ Metody jQuery HTML/CSS

Przykład

Wstaw zawartość na końcu wszystkich <p> elementów:

$("button").click(function(){
  $("p").append("<b>Appended text</b>");
});

Definicja i użycie

Metoda append() wstawia określoną zawartość na końcu wybranych elementów.

Wskazówka: Aby wstawić treść na początku wybranych elementów, użyj metody prepend() .


Składnia

$(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 element

Spróbuj sam - przykłady


Wstaw zawartość za pomocą metody append().


Za pomocą funkcji wstaw zawartość na końcu wybranych elementów.


❮ Metody jQuery HTML/CSS