wrap
英[ræp] 美[ræp]
vt. Wrap; wrap; wrap with... (or bandage, cover, etc.); cover
n. Lap blanket, shawl, scarf, scarf, headscarf, blouse, jacket, coat; wrapping paper;
vi. Winding, coiling (usually used in conjunction with over, around, etc.) ; Wrap up, wrap up; put on (clothes, etc.)
jquery wrap() method syntax
Function: wrap() method places each selected element in the specified HTML content or element.
Syntax: $(selector).wrap(wrapper)
Parameters:
| Parameter | Description |
| wrapper | Required. Specifies the content that wraps the selected element. Possible values: HTML code - e.g. ("<div></div>") New element - e.g. (document.createElement("div")) Existing element - e.g. ($(".div1")) Existing elements will not be moved, only copied and wrapped around the selected element. |
Use functions to wrap elements: Use functions to specify the content to be wrapped around each selected element.
Syntax: $(selector).wrap(function())
Parameters:
| Parameters | Description |
| function() | Required. Specifies a function that returns the wrapped element. |
jquery wrap() method example
<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/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>Click the "Run instance" button to view the online instance
