Metoda jQuery insertAfter()

❮ Metody jQuery HTML/CSS

Przykład

Wstaw element <span> po każdym <p> elemencie:

$("button").click(function(){
  $("<span>Hello world!</span>").insertAfter("p");
});

Definicja i użycie

Metoda insertAfter() wstawia elementy HTML po wybranych elementach.

Wskazówka: Aby wstawić elementy HTML przed wybranymi elementami, użyj metody insertBefore() .


Składnia

$(content).insertAfter(selector)

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

Note: If content is an existing element, it will be moved from its current position, and inserted after the selected elements.
selector Required. Specifies where to insert the content

Spróbuj sam - przykłady


Jak używać metody insertAfter() do wstawiania istniejącego elementu po każdym zaznaczonym elemencie.


❮ Metody jQuery HTML/CSS