A
Andy
Hi,
I have obtained an array of nodear of consecutive sibling nodes in a
dom. I have a function which creates a new span element replaces the
first element of the array in the dom with this span tag, and then
iterates the rest of the array, removing a node from its parent and
appending to the span tag. The result is that I have created a span
element around a sequence of sibling nodes in the dom, and then I can
apply a style to them.
function WrapRangeSpan (win, nodear)
{
var node1 = nodear[0];
var parent = node1.parentNode;
var span = win.document.createElement('span');
parent.replaceChild(span, node1);
span.appendChild(node1);
for (var j = 1; j < nodear.length; j++) {
var node = nodear[j];
parent.removeChild(node);
span.appendChild(node);
}
return span;
}
This works great. Can someone tell me how to reverse this process?
I.e. given such a span that I have created, I want to remove it from
the dom, and then insert its children where the span is.
Thanks,
Andy
I have obtained an array of nodear of consecutive sibling nodes in a
dom. I have a function which creates a new span element replaces the
first element of the array in the dom with this span tag, and then
iterates the rest of the array, removing a node from its parent and
appending to the span tag. The result is that I have created a span
element around a sequence of sibling nodes in the dom, and then I can
apply a style to them.
function WrapRangeSpan (win, nodear)
{
var node1 = nodear[0];
var parent = node1.parentNode;
var span = win.document.createElement('span');
parent.replaceChild(span, node1);
span.appendChild(node1);
for (var j = 1; j < nodear.length; j++) {
var node = nodear[j];
parent.removeChild(node);
span.appendChild(node);
}
return span;
}
This works great. Can someone tell me how to reverse this process?
I.e. given such a span that I have created, I want to remove it from
the dom, and then insert its children where the span is.
Thanks,
Andy