You should be able to just do .toString() on it. See also: http://developer.mozilla.org/en/docs/DOM:Selection
Regards, Martijn
Post by h***@gmail.com I have a selection object (and I can do range from it). How to get HTML code of this selection or range? _______________________________________________ dev-tech-dom mailing list https://lists.mozilla.org/listinfo/dev-tech-dom
-- Martijn Wargers Help Mozilla! http://weblogs.mozillazine.org/qa/ http://www.mozilla.org/contribute/
Post by h***@gmail.com I have a selection object (and I can do range from it). How to get HTML code of this selection or range?
Kind of a hack but in a HTML document you can do e.g.
var selection = window.getSelection(); var range = selection.getRangeAt(0); if (range) { var div = document.createElement('div'); div.appendChild(range.cloneContents()); alert(div.innerHTML); }
Post by Martin Honnen Kind of a hack but in a HTML document you can do e.g. var selection = window.getSelection(); var range = selection.getRangeAt(0); if (range) { var div = document.createElement('div'); div.appendChild(range.cloneContents()); alert(div.innerHTML); }
Hi, I know this subject is almost 3 years old, but I'm looking for the same solution, tried the patch, and it doesn't work for me: still getting text with no HTML (FF 3.5) Have you found another solution?
Post by Martin Honnen Kind of a hack but in a HTML document you can do e.g. var selection = window.getSelection(); var range = selection.getRangeAt(0); if (range) { var div = document.createElement('div'); div.appendChild(range.cloneContents()); alert(div.innerHTML); }
Forget this message and excuse me. I do get the HTML. My mistake...
Post by schnee Hi, I know this subject is almost 3 years old, but I'm looking for the same solution, tried the patch, and it doesn't work for me: still getting text with no HTML (FF 3.5) Have you found another solution?
Post by Martin Honnen Kind of a hack but in a HTML document you can do e.g. var selection = window.getSelection(); var range = selection.getRangeAt(0); if (range) { var div = document.createElement('div'); div.appendChild(range.cloneContents()); alert(div.innerHTML); }