SIGN UP MEMBER LOGIN:    
ARTICLE

Append and Wrap using JQuery

Posted by Shinuraj Articles | JQuery February 06, 2011
Using Append and Wrap in JQuery
Reader Level:
 


Try the code below to Append one paragraph and wrap the existing div inside another div using jQuery:

Add the following code to the head section:

<head>
<title>jQuery wrapper</title>
<script type="text/javascript" src="./js/jquery-1.4.4.js"></script>
<script type="text/javascript">
 $(document).ready(function() {
 
  var dvWrap = $("#dvWrap");
  
var wrapper = dvWrap.wrap("<div></div>");
  
wrapper.css("border", "10px solid red");
  
wrapper.css("padding", "5px");
  
var inner = $("<p>This paragraph added with jQuery</p>");
  
inner.css("color", "blue");
  
inner.click(function(){alert("hello");});
  
wrapper.append(inner);
});
</script>
</head>

Add the following code to the body section:

<body>
<div id="dvWrap">
  <
h1>This is wrapped with a red box drawn by jQuery</h1>
</
div>
</body>

You can download the working sample attached here.

Thanks

Shinu

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor