Categories: jQuery

jQuery wrap() Method

Share

jQuery wrap Method wraps specified HTML element(s) around each element in the set of matched elements.

This wrapping process is very useful for injecting any additional structure into a document, without destroying the original semantic qualities of the document.

Possible values are:

  • HTML elements
  • jQuery objects
  • DOM elements

This is the simple syntax to use this method.

selector.wrap( html )

Parameters

elem – A string of HTML which will be created on the fly and wrapped around each target.

Following is a simple example with a simple usage of this method.

<div class="main">
<div class="sub">John Doe</div>
<div class="sub">Jane Doe</div>
</div>

Read Also:

Now, .wrap() can insert an HTML structure around the each inner <div> elements as below:

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

The result will be:

<div class="main">
<div class="wrap"><div class="sub">John Doe</div></div>
<div class="wrap"><div class="sub">Jane Doe</div></div>
</div>

For more information go to jQuery references.

Recent Posts

Optimize Your Hormonal Balance: Enclomiphene Citrate for Enhanced Wellness

Hormonal balance plays a pivotal role in overall well-being, influencing various aspects of health, from…

18 hours ago

Paul Kanes Explores the World of Canine Companionship through Dog Walking

Dog walking is an excellent way to maintain your furry friend's camaraderie and provides many…

20 hours ago

Top 5 Must-Have Features Every Mobile App Needs to Succeed

Introduction Businesses understand the diverse requirements of mobile applications, which provide a competitive advantage. There…

1 day ago

IoT Data Analytics: Ways to Gain Value from IoT Data

The Internet of Things (IoT) has recently changed the world. It links gadgets together and…

1 day ago

The Rise of NFTs: Exploring the Impact of Non-Fungible Tokens on the Digital Economy

NFTs, or Non-Fungible Tokens, are revolutionizing the digital economy. These unique digital assets, authenticated through…

2 days ago

What to Ask Before You Hand Your Laptop For Repairing

It is safe to say that if you are in need of a good laptop…

2 days ago