0

I'm working with rangy and got a question relating to selection and its cross browser behaviour.

I've got some elements inside a div (e.g. a hyperlink) and I'd like to be able to select the outerHTML when clicking inside this element.

<div>Lorem ipsum <a href="#">duo dolores</a> tempor.</div>

So I tried range.selectNode() and expected the whole node to be selected so that selection.toHtml() would give me the outerHTML of the hyperlink. To get the innerHTML I would call range.selectNodeContents(). And this is how it works in IE 9.

But in Chrome in both cases only the innerHTML is being selected. Is there a bug in rangy plugin (which should be cross browser) or am I doing something wrong?

Check this fiddle to see what I mean. First open it in IE 9, place the caret inside the hyperlink and click on the 1st button (check output of selection.toHtml()). Then place caret again inside the hyperlink and click on 2nd button (check output again). Afterwards do the same in Chrome.

vso
  • 199
  • 2
  • 17
  • Just found [this answer](http://stackoverflow.com/a/11442433/1794328). Is it still the same problem in my case? – vso Jan 08 '13 at 11:18
  • Yes, it's the same problem. If you check the range after `selectNode()` you'll see that it has done what you expect; adding the range to the selection is what changes it. – Tim Down Jan 08 '13 at 18:10

0 Answers0