Here is my code:
Sorry for the quality and formatting.
Basically, what i want is to copy all the contents (text,objects) of a div into another div.
div #results contains a google map and some other objects.
i’ve tried using .clone also but its not working. All text gets copied correctly but the google map in #results2 does not show up.
I need to do these, because i will have to sort the divs according to a value and display them in a page and also do a system of navigation.
/*created_div=new Object();*/
var my_div=create_div_test(p[z],my_traversed_edge,board,alight,visited_bus,tot_distance,tot_time);
if(my_div!=null){
v='#';
v+='results';
$('#results').html(my_div);
var x='animate';
var v='#animater';
v+=div_id;
x+=div_id;
var visited_id='#visited';
visited_id+=div_id;
created_div.my_id=div_id;
var map=create_map(div_id);
var poly=retrieve_results_edges(bus_stops_visited,map);
var strVar="";
strVar += "<span class=\"animate\">";
strVar += "<input type=\"button\" id="+x+" name=\"animate\" value=\"Animate\" \/>";
strVar += "<\/span>";
$(v).append(strVar);
retrieve_the_stops(bus_stops_visited,map);
var str_var=show_visited_stops(bus_stops_visited,map);
$(visited_id).append(str_var);
$('#'+x).bind('click',{poly:poly,map:map}, function(event) {
animate(event.data.poly,event.data.map)
});
set_map(map);
set_polyline_color(my_traversed_edge,bus_stops_visited,map);
$('#results2').html($('#results').html());
/*created_div.htmlContent=$('#results').clone();
$('#results').empty();
created_div.totaldistance=tot_distance;
created_div.totaltime=tot_time;
my_divs.push(created_div);*/
}
}
You can’t arbitrarily copy objects that are used by other people’s code (e.g. a Google Map) because how you would make that work depends upon the specific code that created or manages the objects.
You can use jQuery’s
.clone()to clone objects you created yourself that are managed by jQuery event handlers and jQuery data and not by any direct DOM references, but objects created or managed by other types of code will have to be recreated with that other code.So, in this case, if you truly want a second copy of the Google Map, you will have to use the Google API to make a new MAP with the same specifications as the first one that you can put in the second location.