Convert this javascript function into jquery [closed]
Could someone convert this plain javascript function to use jquery functions? Thanks!
move_object = function (from, to) {
var i, // local variable
childnodes_length; // number of child nodes
// test if "from" cell is equal to "to" cell then do nothing
if (from === to) {
return;
}
// define childnodes length before loop (not
// in loop because Node开发者_如何学PythonList objects in the DOM are live)
childnodes_length = from.childNodes.length;
// loop through all child nodes
for (i = 0; i < childnodes_length; i++) {
// '0', not 'i' because NodeList objects in the DOM are live
to.appendChild(from.childNodes[0]);
}
};
This should do it:
$(from).contents().appendTo(to);
Live demo: http://jsfiddle.net/simevidas/YxcYC/
精彩评论