jQuery replaceWith() 方法
實例
把第一個 <p> 元素替換為新的文本:
$("button").click(function(){
$("p:first").replaceWith("Hello world!");
});
定義和用法
replaceWith() 方法把被選元素替換為新的內容。
語法
$(selector).replaceWith(content,function(index))
| 參數 | 描述 |
|---|---|
| content | 必需。規定要插入的內容(可包含 HTML 標籤)。
可能的值:
|
| function(index) | 可選。規定返回替換內容的函數。
|
更多實例
使用函數替換內容
如何使用函數替換把被選元素替換為新的內容。

jQuery HTML/CSS 方法