0

I'm trying to highlight an image when it's clicked in a contenteditable iframe. I've tried this but nothing happens:

var iframeDoc = editor.contentDocument || editor.contentWindow.document;
var range = rangy.createRange(iframeDoc);
var sel = rangy.getIframeSelection(editor);

range.setStartBefore(img);
range.setEndAfter(img);
sel.setSingleRange(range);

Is there something I'm missing, or is this not possible? I'm using chrome but want to target as many browsers as possible.

TimCodes.NET
  • 4,601
  • 1
  • 25
  • 36
  • Works for me: http://jsfiddle.net/timdown/VZnaa/1/. Is `img` definitely a reference to the correct image? COuld the selection be being destroyed before you see it? – Tim Down Oct 29 '13 at 09:57
  • Thanks for your comment Tim, I'm unsure what the problem was, I was using version 1.2.2, copied your code from the fiddle and it still wasn't working - updated to the latest 1.3 alpha and it works now. It may have been to do with this issue: https://code.google.com/p/rangy/issues/detail?id=138. Thanks for all you do with rangy, its a great tool. – TimCodes.NET Oct 29 '13 at 20:50

0 Answers0