replaceWith(content|fn) :将所有匹配的元素替换成指定的HTML或DOM元素。
replaceWith(content|fn) 方法:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<span>Hello</span>
<b>Hello</b>
<i>Hello</i>
<script>
$("span,b,i").replaceWith("<h3>Word</h3>")
</script>
</body>
</html>
replaceAll(selector):用匹配的
replaceAll(selector)方法:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<span>Hello</span>
<b>Hello</b>
<i>Hello</i>
<script>
$("<h3>Word</h3>").replaceAll("span,b,i");
</script>
</body>
</html>
元素替换掉所有 selector匹配到的元素。