Click here to Skip to main content
15,888,590 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to be copy of one HTML div content into another HTML page div
Posted
Comments
Thanks7872 2-Feb-15 5:43am    
$("#Second-div-id").html($("#First-div-id").html());
kumarravishankar 2-Feb-15 5:57am    
Sir, actually i have two different html page i.e demo.html and demo1 , and my requirement to copy demo.html into demo1.html.
Sinisa Hajnal 2-Feb-15 6:09am    
Put that HTML into Session / ViewBag variable or post needed data to the second page.

Better solution would be to use only relevant data and rebuild the html at the destination.
How you are planning to do it?

In first page, simply fetch your data of div into a variable:

var divData=$("#divId").html();


now put it into local storage:

localStorage.setItem("divdata",divData);


now in second page:

var divDataBack= localStorage.getItem("divData");
 
Share this answer
 
jQuery has a .load() which may help.

http://api.jquery.com/load/[^]
Quote:

.load( url [, data ] [, complete ] )
Description: Load data from the server and place the returned HTML into the matched element.
JavaScript
//try something like this
$("#DivIDonDemo1").load( "/demo.htm #DivIDfromDemo ");
//Ensure the relevant htm page exists and the page has element with the specified id
 
Share this answer
 
Comments
jaket-cp 3-Feb-15 4:13am    
What is with the down vote on this solution?
Comment would be nice.
Can not see how it can be improved, or what is wrong with it.
I am here to help and learn at the end of the day.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900