CodesJava

Easy learning with example program codes

jQuery wrapAll()


jQuery wrapAll() method wraps the specified HTML elements around all the selected elements.

Syntax:

$(selector).wrapAll(wrappingElement)

Wrapping Element:

  • It is a compulsory parameter.
  • It is used to specify the HTML elements to wrap around the selected elements.
  • Its can accept HTML elements, jQuery objects and DOM elements as a value.

 

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(){  
$("button").click(function(){  
$("p").wrapAll("<em></em>");  
});  
});  
</script>  
</head>  
<body>  
<p>Hello!</p>  
<p>Nice to see you.</p>  
<button>Wrap All</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(){  
	$("button").click(function(){  
    	$("p").wrapAll("<div></div>");  
	});  
});  
</script>  
<style>  
div{background-color: turquoise;
	}  
</style>  
</head>  
<body>  
<p>Hello</p>  
<p>Guys!</p>  
<button>Wrap All</button>  
</body>  
</html>

Try it

JS Bin on jsbin.com

Sign Up/ Sign In
Ask a Question


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