jquery wrapAll() method


  Translation results:

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; confidential

vi. Winding, coiling (usually used in conjunction with over, around, etc.) ; wrap up, wrap up; put on (clothes, etc.)

all

英[ɔ:l]   美[ɔl]   

adj. all; everything; all kinds; extreme, as much as possible

pron.all;everyone;everyone,everything;all situations

adv.entirely;completely; each;very

n.all;[often used as A-]whole;[often used with my, your, his, her, etc.](someone) everything

jquery wrapAll() methodsyntax

Function: wrapAll() places all selected elements in the specified HTML content or element.

Syntax: $(selector).wrapAll(wrapper)

Parameters:

ParameterDescription
wrapper Required. Specifies the content that wraps the selected element. Possible values: HTML code - e.g. ("<div></div>") New DOM element - e.g. (document.createElement("div")) Existing element - e.g. ($(".div1" ))Existing elements will not be moved, but will only be copied and wrapped around the selected element.

jquery wrapAll() methodexample

<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").wrapAll("<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>
Run instance »

Click the "Run instance" button to view the online instance

Home

Videos

Q&A