jQuery Tutorial Tutorials - jQuery .wrapAll() method

jQuery .wrapAll() method

The .wrapAll() method in jQuery is used to wrap a new HTML structure around all the matched elements.

jQuery .wrapAll() method Syntax

.wrapAll(wrappingElement)
.wrapAll(function)

wrappingElement specifying the structure to wrap around the matched elements.
function is a callback function returning the HTML content or jQuery object to wrap around all the matched elements.

.wrapAll(wrappingElement)

example

Create a div element to wrap around all of the paragraph.
HTML

<div class="container">
    <p>JavaScript Tutorial</p>
    <p>Learn jQuery on Lautturi.com</p>
</div>

jQuery

$("p").wrapAll("<div class='wrap'></div>");

Result

<div class="container">
    <div class="wrap">
        <p>JavaScript Tutorial</p>
        <p>Learn jQuery on Lautturi.com</p>
    </div>
</div>

Try now

Date:2019-08-25 10:54:30 From:www.Lautturi.com author:Lautturi