Use javascript to extend a DOM Range to cover partially selected nodes

Posted by ko-dos on Stack Overflow See other posts from Stack Overflow or by ko-dos
Published on 2010-03-19T12:29:16Z Indexed on 2010/03/19 12:31 UTC
Read the original article Hit count: 147

Filed under:

I'm working on a rich text editor like web application, basically a XML editor written in javascript.

My javascript code needs to wrap a selection of nodes from the contentEditable div container. I'm using the methods described at MDC. But since I need to synchronize the div containers content to my XML DOM I would like to avoid partial selections as described in w3c ranges:

<BODY><H1>Title</H1><P>Blah xyz.</P></BODY

............^----------------^............

This selection starts inside H1 and ends inside P, I'd like it to include H1,P completely.

Is there an easy way to extend the selection to cover partially selected children completely?

(The code doesn't need to work with opera/IE)

© Stack Overflow or respective owner

Related posts about JavaScript