"); }); ``` --- ##"> "); }); ``` --- ##" />
Easy Tutorial
❮ Traversing Parentsuntil Html Before ❯

jQuery wrap() Method

jQuery HTML/CSS Methods

Example

Wrap each <p> element in a <div> element:

$("button").click(function(){
    $("p").wrap("<div></div>");
});

Definition and Usage

The wrap() method wraps specified HTML elements around each selected element.


Syntax

Parameter Description
wrappingElement Required. Specifies the HTML element to wrap around each selected element. Possible values: HTML element<br> jQuery object<br> DOM element
function (index) Optional. Specifies a function that returns the wrapping element. index - Returns the index position of the element in the set.

More Examples

Create New Element with DOM

Wrap Elements Using a Function

Wrap and Unwrap Elements


jQuery HTML/CSS Methods

❮ Traversing Parentsuntil Html Before ❯