jquery - How to properly copy data from div to new window dynamically

I have a problem. Im trying to create a very simple print preview that when the user clicks the Print Preview button it will open a new window and copies the data I wanted. There are some elements like the checkbox that I don't want to include but Im able to do it successfully. My problem is when the new window is loaded the original div is also altered. Like the checkboxes are removed in the original div and the Print button also appears.

I want my original div which is divData to remain the same. I don't have problem with the new window.

Btw my jquery codes are below:

        $("#btnPrintPreview").click (function () {
            var printContents = new $("#divData");
            var myWindow = window.open("", "popup","width=1000,height=600,scrollbars=yes,resizable=yes," +  
            var doc = myWindow.document;
            var button = "<input type='button' id='btnPrint' value='Print' style='float: right;' onclick='window.print();'/>";

To see my demo here is the link http://jsfiddle.net/dU7et/.

PS: Please check the main div after clicking the Print Preview.

Please help me....


For this to do what you are wanting change the following line to:

// Before:
var printContents = new $("#divData");
// After:
var printContents = $("#divData").clone();

See http://api.jquery.com/clone/ for further reference.

Need Your Help

How do travel websites implement the sorting of search results?

database design-patterns caching sorting

For example you make a search for a hotel in London and get 250 hotels out of which 25 hotels are shown on first page. On each page user has an option to sort the hotels based on price, name,

How do I find the number of namespaces in Hazelcast?

java cluster-computing in-memory-database hazelcast

Using ns command i created a number of namespaces in my console. I have a problem now. I have created more than 5 namespaces and I have lost track of them ! I want to see the number of namespaces ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.