Copy or clone an HTML element in a prototype

I have two html selection windows where elements are moved from left to right, now I want to change the behavior so that the elements are copied from right to left. I tried Oject.clone(o) and .cloneNode(true) with the prototype library. It makes my browser freeze

Currently, code that moves elements from left to right looks like this:

 $('left').appendChild($('right').options.item($('right').selectedIndex)); 

How can I change this so that there is a copy of the elements from left to right, and not the actual move.

+4
source share
1 answer

Instead of Object.clone() use Element.clone()

 var selected = $('right').options.item($('right').selectedIndex); var copy = Element.clone(selected, true); $('left').appendChild(copy); 

Documentation: http://api.prototypejs.org/dom/Element/clone/

+3
source

Source: https://habr.com/ru/post/1391202/


All Articles