views:

22

answers:

1

I'm copying a range from the page and pasting it back elsewhere, but this becomes problematic when it includes a piece of the page that I don't want to copy. Is there a good way to remove nodes from a range by id? Or if not, in the event that there are two nodes on the page with the same id, is there any way to identify one over the other (ie, via first specifying a unique parent id?)

Note: JavaScript only please - I can't use a library for this solution.

+1  A: 

If you're talking about DOM Ranges, the solution is to split the Range around the node you want to exclude, giving you two Ranges.

// Assuming you have a Range stored in a variable called range and
// a node you want to exclude in a variable called node
var newRange = range.cloneRange();
range.setEndBefore(node);
newRange.setStartAfter(node);

This won't work in IE, which has an entirely different way of representing ranges.

Tim Down