jQuery insertAfter() Metode
Contoh
Masukkan elemen <span> setelah setiap elemen <p>:
$("button").click(function(){
$("<span>Hello world!</span>").insertAfter("p");
});
Definisi dan Penggunaan
Metode insertAfter() menyisipkan elemen HTML setelah elemen yang dipilih.
Tip: Untuk menyisipkan elemen HTML sebelum elemen yang dipilih, gunakan metode insertBefore() .
Sintaksis
$(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 |
Cobalah Sendiri - Contoh
Cara menggunakan metode insertAfter() untuk menyisipkan elemen yang ada setelah setiap elemen yang dipilih.