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.
wrap()
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:
or say if you would like to check a certain level of depth and add element accordingly you could also do that as follows:
<script>$("span").wrap("<div class="test"></div>");</script>
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'>
<p>
Change Me
</p>
</div>
<div class='second'>
<p>
Do not Change Me
</p>
</div>
we would do
<script>$(".first p").wrap("<div class='third'></div>");</script>