jQuery and ASP.NET

February 7, 2010

Exploring the unwrap() method in jQuery 1.4




As given in the jQuery API documentation, the .unwrap() method removes the element's parent. The matched elements (and their siblings, if any) replace their parents within the DOM structure.

Here’s an example:

<html>
<
head>
<
title>Exploring the unwrap method</title>
<
style type="text/css">
.divOne{
height:40px;
width:100px;
background-color:#808080;
}
.divTwo{
height:20px;
width:50px;
background-color:#f0f0f0;
}
</style>
<
script language="javascript" type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js">
</
script>
<
script language="javascript" type="text/javascript">
$(function() {
$("#btn").click(function() {
jQuery('.divTwo').unwrap();
});
});
</script>
</
head>
<
body>
<
form>
<
div class="divOne">
<
div class="divTwo">

</
div>
</
div>
<
input id="btn" type="button" value="Unwrap" />
</
form>
</
body>
</
html>

If you run the code, the display is similar to the following:

image

Clicking on Unwrap, calls the unwrap() method on the jQuery object representing divTwo. The output is as follows:

image

As shown above, unwrap removes the parent of divTwo.

See a Live Demo



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Exploring the unwrap() method in jQuery 1.4"
 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions