Working with wrap in jQuery, (How to add an element around another element in jQuery)

jQuery is a multi-browser JavaScript library designed to simplify the client-side scripting of HTML. It was released in January 2006 at BarCamp NYC by John Resig. Used by over 55% of the 10,000 most visited websites, jQuery is the most popular JavaScript library in use today. Here we will discuss 5 quick jQuery examples.


This function is used to wrap a given element with the newly provided element. Say if you want to wrap all <span> with a <div>  with class “test” you would do something like: 
<script>$("span").wrap("<div class="test"></div>");</script>
or say if you would like to check a certain level of depth and add element accordingly you could also do that as follows:

For example if we would like to append a “div” tag with class “third” to the ‘p’ tag of the first div as shown, 
<div class='first'>
Change Me
<div class='second'>
Do not Change Me

we would do
 <script>$(".first p").wrap("<div class='third'></div>");</script>