jQuery append() Methode

❮ jQuery HTML/CSS-methoden

Voorbeeld

Voeg inhoud toe aan het einde van alle <p> elementen:

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

Definitie en gebruik

De methode append() voegt gespecificeerde inhoud in aan het einde van de geselecteerde elementen.

Tip: Gebruik de prepend()- methode om inhoud aan het begin van de geselecteerde elementen in te voegen.


Syntaxis

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

Probeer het zelf - Voorbeelden


Voeg inhoud in met de append() methode.


Een functie gebruiken om inhoud aan het einde van de geselecteerde elementen in te voegen.


❮ jQuery HTML/CSS-methoden