views:

47

answers:

2

HI

I want to copy the content of a selected div to another div with jquery clone. but I dont want to append it anywhere

what I mean is when we make a clone of a div with jquery (correct me if i am wrong) we have to set its position and it will dynamically create a new division which is displayed.

but I want to get the content of a selected div and copy it to another pre-set div

thanx in advance

+3  A: 
var a = $('#selector').html();
var b = $('#selector').html(a);

not sure I understood you properly but I think thats what you meant :)

Val
This could also be written: `$('#selectorDestination').html($('#selectorSource').html());`. Avoiding declaring variables.
Dustin Laine
Only thing we should be cautious is we shouldn't dupliate the ids in the html
gov
@dustin yes thats the same thing but i thought since he asked not to put on the dom "i don't want to append it anywhere" :) thats the best way forward
Val
@val thanx for it , that's what i need.
pahnin
A: 

I don't agree. Clone can save data without applying to the content.

Look here:

http://www.jsfiddle.net/dactivo/FqffM/

var mylayer=$('.hello').clone();

Here you can manage the variable "mylayer" as you want, and it's not in the DOM.

netadictos
anyway val's method is simple and I think it suits me
pahnin
Of course, html() is a great method but it's good to know that clone() can be managed without including in the DOM
netadictos
`Clone` also copies the container element, which I do not think the @pahnin wants.
Dustin Laine
yes thats the problm i faced
pahnin
Ok, I thought the real problem was you didn't want to set its position. html() is great for this.
netadictos