jQuery replaceWith() Metode
Contoh
Ganti elemen <p> pertama dengan teks baru:
$("button").click(function(){
$("p:first").replaceWith("Hello world!");
});
Definisi dan Penggunaan
Metode replaceWith() menggantikan elemen yang dipilih dengan konten baru.
Sintaksis
$(selector).replaceWith(content,function(index))
Parameter | Description |
---|---|
content | Required. Specifies the content to insert (can contain HTML tags)
Possible values:
|
function(index) | Optional. Specifies a function that returns the content to replace
|
Cobalah Sendiri - Contoh
Cara menggunakan fungsi untuk mengganti elemen yang dipilih dengan konten baru.