Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Replace range content

183 views
Skip to first unread message

homers...@gmail.com

unread,
Jan 6, 2007, 4:15:09 PM1/6/07
to
I have selection range object. Now I need to replace it contents with
my HTML code. How can I do that?

For example IE has Range.pasteHTML method, and what about FF?

Martin Honnen

unread,
Jan 7, 2007, 8:07:57 AM1/7/07
to
homers...@gmail.com wrote:
> I have selection range object. Now I need to replace it contents with
> my HTML code. How can I do that?

Delete the existing contents and create the new contents with the DOM e.g.

var selection = window.getSelection();
var range = selection.getRangeAt(0);
if (range) {
range.deleteContents();
var newContents = document.createElement('span');
newContents.textContent = 'Kibology for all.';
range.insertNode(newContents)
}


--

Martin Honnen
http://JavaScript.FAQTs.com/

Alex Vincent

unread,
Jan 11, 2007, 11:51:02 AM1/11/07
to

Martin, I've actually been thinking about this quite a bit lately -- in
the context of transactions (do, undo, redo). It's not clear at all how
to do that correctly. Can you give me some advice?

Alex

0 new messages