Latest web development tutorials

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方法