1. 程式人生 > >jQuery文檔操作之修改操作

jQuery文檔操作之修改操作

dom all () 指定 lec eal 標簽 pla replace

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");

jQuery文檔操作之修改操作