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:

  • HTML elements
  • jQuery objects
  • DOM elements
function(index) Optional. Specifies a function that returns the content to replace
  • index - Returns the index position of the element in the set

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