CodesJava

Easy learning with example program codes

jQuery unwrap()


The jQuery unwrap() method removes the parent element of the selected elements.

Syntax:

$(selector).unwrap() 

Example 1

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
<script>  
 
$(document).ready(function(){  
	$("#btn1").click(function(){  
$("p").wrap("<em></em>");  
});  
 $("#btn2").click(function(){  
    	$("p").unwrap();  
	});  
});  
</script>  
</head>  
<body>  
<p>Hello!</p>  
<p>Nice to see you.</p>  
<button id="btn1">Wrap</button>  
<button id="btn2">Unwrap</button>
</body>  
</html>

Try it

JS Bin on jsbin.com

Example 2

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
	$("#btn1").click(function(){  
    	$("p").wrapAll("<div></div>");  
	});  
	$("#btn2").click(function(){  
    	$("p").unwrap();  
	});  
});  
</script>  
<style>  
div{background-color: turquoise;
	}  
</style>  
</head>  
<body>  
<p>Hello</p>  
<p>Guys!</p>  
<button id="btn1">Wrap All</button>  
<button id="btn2">Unwrap</button>
</body>  
</html>

Try it

JS Bin on jsbin.com

Example 3

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
	$("#btn1").click(function(){  
    	$("p").wrapAll("<div></div>");  
	});  
	$("#btn2").click(function(){  
    	$("p").unwrap();  
	});  
});  
</script>  
<style>  
div{background-color: turquoise;width: 120px;  
	height: 200px;    
	margin: 5px;padding:2px; border:2px solid red;
}  
</style>  
</head>  
<body>  
<p>Hello</p>  
<p>Guys!</p>  
<button id="btn1">Wrap All</button>  
<button id="btn2">Unwrap</button>    
</body>  
</html>

Try it

JS Bin on jsbin.com

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki