Metoda jQuery insertBefore().
Příklad
Před každý prvek <p> vložte prvek <span>:
$("button").click(function(){
$("<span>Hello world!</span>").insertBefore("p");
});
Definice a použití
Metoda insertBefore() vloží prvky HTML před vybrané prvky.
Tip: Chcete-li vložit prvky HTML za vybrané prvky, použijte metodu insertAfter() .
Syntax
$(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 |
Zkuste si to sami - příklady
Jak použít metodu insertBefore() k vložení existujícího prvku před každý vybraný prvek.