Phương thức jQuery ReplaceWith ()
❮ Phương thức HTML / CSS jQuery
Thí dụ
Thay thế phần tử <p> đầu tiên bằng văn bản mới:
$("button").click(function(){
$("p:first").replaceWith("Hello world!");
});
Định nghĩa và Cách sử dụng
Phương thức ReplaceWith () thay thế các phần tử đã chọn bằng nội dung mới.
Cú pháp
$(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
|
Hãy tự mình thử - Ví dụ
Cách sử dụng hàm để thay thế các phần tử đã chọn bằng nội dung mới.
❮ Phương thức HTML / CSS jQuery