Hi guys,

while looking for a way to clone an element, I stumbled upon this
thread from 2007:

http://groups.google.com/group/prototype-core/browse_thread/thread/9e943e4b54780d97

Any chance this is some when gonna end up in the core? I think this is
function might be pretty useful sometimes.

Apart from cloning an element I also needed to move an element from
one div to another and I came up with this function which is basically
a wrapper for the insert() function:

Element.addMethods({
        appendTo: function(element, newParent, position) {
                element = $(element);
                newParent = $(newParent);
                switch(position) {
                        case 'top':
                                newParent.insert({top: element});
                                break;
                        case 'bottom':
                                newParent.insert({bottom: element});
                                break;
                        case 'before':
                                newParent.insert({before: element});
                                break;
                        case 'after':
                                newParent.insert({after: element});
                                break;
                }
                return element;
        }
});

I don't like the switch part very much and tried to use the position
variable directly but that somehow didn't work...anyone knows why?

Element.addMethods({
        appendTo: function(element, newParent, position) {
                element = $(element);
                newParent = $(newParent);
                newParent.insert({position: element});
                return element;
        }
});
$('test').appendTo('test2', 'top');

Using this function Firebug shows this error: "insert is not a
function".

Anyway, maybe someone else finds this useful aswell :)

David

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to