How to use HTML Wrap Method in JQuery

This article describe about HTML Wrap Method in JQuery.
  • 1878

HTML wrap() method in jQuery

  • wrap() method wraps determine HTML element around each selected element.

Using a Function

  • wrap() method using a function to determine what to wrap around each selected element.

Syntax

This is the simple syntax to use this method:

$(selector).wrap(function())

Example

The following example show the use of wrap() method.

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function ()

{

        $("button").click(function ()

 {

            $("p").wrap(function () {

                return "<div></div>"

            });

        });

    });

 

</script>

<style type="text/css">

div{background-color:red;padding:10px;}

</style>

</head>

<body>

<p>This is a JQuery.</p>

<button>Wrap effect after click this button</button>

</body>

</html>

Output1

op1.jpg

Output2

op2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.