jQuery replaceAll() 方法

jQuery HTML/CSS 方法 jQuery HTML/CSS 方法

實例

把最後一個 <p> 元素替換為 <span> 元素:

$("button").click(function(){ $("<span>Hello world!</span>").replaceAll("p:last"); });


定義和用法

replaceAll() 方法把被選元素替換為新的 HTML 元素。


語法

$(content).replaceAll(selector)

參數 描述
content 必需。規定要插入的內容(必須包含 HTML 標籤)。
selector 必需。規定哪一個元素將被替換。


jQuery HTML/CSS 方法 jQuery HTML/CSS 方法