Hi,
I would like to clone a tag using Javascript (without using any external frameworks like jQueries, so please limit the answer to plain Javascript)
Here is my requirement. Say I have a random div like the following in the document,
<div id='anEmptyDiv' style="display:none">
<div>
Lorem Ipsum
</div>
</div>
And I should be able to do something like this,
var customDiv = document.getElementyById('anEmptyDiv');
var copyDiv = clone(customDiv);
copyDiv.id = 'a_valid_id';
copyDiv.style.display = 'block';
There is a reason behind I this question. I have a structured DIV tag which I want to use many times when some event occurs. I want the structure alone and I dont intend to create the DOM tree everytime. Is this possible in Javascript?