Metoda jQuery insertBefore()
Przykład
Wstaw element <span> przed każdym elementem <p>:
$("button").click(function(){
$("<span>Hello world!</span>").insertBefore("p");
});
Definicja i użycie
Metoda insertBefore() wstawia elementy HTML przed wybranymi elementami.
Wskazówka: Aby wstawić elementy HTML po zaznaczonych elementach, użyj metody insertAfter() .
Składnia
$(content).insertBefore(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 before the selected elements. |
selector | Required. Specifies where to insert the content |
Spróbuj sam - przykłady
Jak używać metody insertBefore() do wstawiania istniejącego elementu przed każdym wybranym elementem.