Hi all,
I was reading in some LightHouse comments about the new swap method on
elements and was wondering if the following is interesting for that
matter. I had it written this way in my simple code:
// nodes to swap (t)arget node, (s)econdary node
swapNodes:
function(t, s) {
var n = t.nextSibling, p = t.parentNode;
s.parentNode.replaceChild(t, s);
p.insertBefore(s, n);
}
so I transformed that in to the suggested prototype syntax (kangax):
Element.addMethods({
swapWith: function(element, other) {
element = $(element);
other = $(other);
if (element !== other) {
var node = element.nextSibling, parent = element.parentNode;
other.parentNode.replaceChild(element, other);
parent.insertBefore(other, node);
}
return element;
}
});
Haven't done any test on this, but the above simpler syntax works well
for me.
--
Diego Perini
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---