wrapAll(Html)方法将匹配集合中的所有元素包装到单个包装元素中。
selector.wrapAll( html )
下面是此方法使用的所有参数的说明
html - 动态创建并环绕每个目标的HTML字符串。
下面是一个简单的示例,一个简单的示例说明了该方法的用法。这将用一个新的正方形-包装所有的正方形
链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/dom-wrapall-html.html
来源:LearnFk无涯教程网
<html> <head> <title>The jQuery Example</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("div").click(function () { var content="<div class='div'></div>"; $("div").wrapAll( content ); }); }); </script> <style> .div{ margin:10px;padding:12px; border:2px solid #666; width:60px;} </style> </head> <body> <p>Click on any square below to see the result:</p> <div class="div" id="destination">THIS IS TEST</div> <div class="div" style="background-color:blue;">ONE</div> <div class="div" style="background-color:green;">TWO</div> <div class="div" style="background-color:red;">THREE</div> </body> </html>
这将产生以下输出-
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)