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
First, select the div element which need to be copy into another div element. Select the target element where div element is copied. Use the append() method to copy the element as its child.
To clone a div and change its id with JavaScript, we can use the cloneNode method on the div. Then we can set the id property of the cloned element to set the ID. to add the div.
The clone() is an inbuilt method in jQuery which is used to make a copy of selected elements including its child nodes, text and attributes. Syntax: $(selector).clone(true|false) Parameter: It accepts an optional parameter which could be either true or false specifies that event handler should be copied or not.
var a = $('#selector').html(); var b = $('#selector').html(a);
not sure I understood you properly but I think thats what you meant :)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With