wrap()包裹被选元素的内容
<!doctype html> <html> <head> <meta charset="utf-8"> <title>修改代码,右边会自动显示结果</title> <!--适应移动端--> <meta name="viewport" content="width=device-width, initial-scale=1"> <!--css样式--> <!--引用jquery库--> <script src="https://s1.pstatp.com/cdn/expire-1-M/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".btn1").click(function(){ $("p").wrap("<div></div>"); }); }); </script> <style type="text/css"> div{background-color:yellow;} </style> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button class="btn1">用 div 包裹每个段落</button> </body> </html>