views:

144

answers:

3

i replace selected text with pasteHTML method (Pastes HTML text into the given text range, replacing any previous text and HTML elements in the range.) in internet explorer.

var ran = Editor.selection.createRange();
ran.pasteHTML('<span style="font-size:20px;">example</span>');

after replacing text, selection dissapears. how to highlight previous selection (text) again ? thanks

+2  A: 

pasteHTML will delete the current selection from the document, so I assume you want to select the span you've replaced it with. To do this, add an ID to the span, move the TextRange to encompass its text and select it, as follows:

var ran = Editor.selection.createRange();
ran.pasteHTML('<span style="font-size:20px;" id="a_random_unique_id">example</span>');

var spanRange = ran.duplicate();
spanRange.moveToElementText( document.getElementById("a_random_unique_id") );
spanRange.select();
Tim Down
thanks tim, this is exactly what i need :)
mm
A: 

please send the answer in my email! I am from Iran and the line is so slow! i need it please help me!

Hboy
You're posting a question as an answer. Please leave a comment instead.
Ikke
A: 

hi if the above code be this:

ran.pasteHTML('<a href='http://www.ok.com'&gt;example&lt;/a&gt;');

and it do not have (id) what is the answer? please guid me thanks

Hboy
Better post this as a new question ("Ask Question" button in the top right of the page). More people will see it that way. Also make clear what you are trying to do and what exactly doesn't work.
sth