Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SurroundContents on a range spanning multiple tags (getRangeAt problem?)

I have a script that (I think) needs to use surroundContents to wrap the selection area. Doing so allows me to append something, and then reassign the range as the selection.

I believe I've narrowed the problem down to a misuse of getRangeAt, but I'm not quite sure how to correct it.

Here's the brief bit of code:

        function getRangeObject(selectionObject) {
        // Moz
        if (selectionObject.getRangeAt) {
            return selectionObject.getRangeAt(0);
        }

And here's line 89 where it throws an error at me:

rangeObject.surroundContents(newNode);

And of course, here's the error:

Error: uncaught exception: [Exception... "The boundary-points of a range does not meet specific requirements." code: "1" nsresult: "0x805c0001 (NS_ERROR_DOM_RANGE_BAD_BOUNDARYPOINTS_ERR)" location: "http://www.latentmotion.com/insertNode/index26.html Line: 89"]

If it's helpful to see the whole thing, you can view the script (so far) here: http://www.latentmotion.com/insertNode/index26.html

And the text selection helper that I was going off of was quirksmode - which doesn't detail the use of multiple ranges, located here.

Thanks in advance for your help.

like image 386
Matrym Avatar asked Dec 06 '25 14:12

Matrym


1 Answers

I think the error message describes the problem well. This section of the DOM Range spec describes what leads to an exception being thrown by a Range when using surroundContents.

like image 169
Tim Down Avatar answered Dec 08 '25 09:12

Tim Down



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!