Search code examples
yui

How to clone the element in YUI3?


I have div element and inside that few more element like UL , span etc.

So, how can i clone the element like jquery clone.

Please don't suggest http://www.jsrosettastone.com/ because i already checked there.


Solution

  • YUI().use('node', function(Y){
       var node = Y.one('#doc');
       var clone = node.cloneNode(true); // true tells it to do a deep clone
    });
    

    It's in the YUI API docs: http://yuilibrary.com/yui/docs/api/classes/Node.html#method_cloneNode