jQuery文档操作之修改操作

replaceWith()

语法: >$(selector).replaceWith(content);

将所有匹配的元素替换成指定的string、js对象、jQuery对象。

// 将所有的h5标题替换成a标签
$("h5").replaceWith("<a href="#">hello world</a>")
//将所有的h5标签替换成id为app的dom元素
$("h5").replaceWith("#app");

replaceAll

语法: >$(selcetor).replaceAll("h2");

解释: 替换所有。将所有的h2标签替换为选中的选中的DOM标签。

// 将所有的h4标签替换为button标签
$("<button>按钮</button>").replaceAll("h4");