---
title: "jquery 控制 wrap(elem)"
author: "KAXU"
date: "2009-02-03T15:03:41Z"
tags: []
slug: "jquery-wrap-elem"
draft: false
lastmod: "2009-02-03T15:03:41Z"
id: 322392
url: "https://kaxu.iteye.com/blog/322392"
---

wrap(elem)

将特殊的‘elem’元素封装在匹配元素集合的每一个元素上

```
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("p").wrap(document.createElement("div"));
  });
  </script>
  <style>
  div { border: 2px solid blue; }
  p { background:yellow; margin:4px; }
  </style>
</head>
<body>
  <p>Hello</p>
  <p>cruel</p>
  <p>World</p>
</body>
</html>
```

 

$("p").wrap(document.createElement("div"));  
将div元素封装在匹配p元素集合的每一个p元素上