javascript - explorer: how to highlight text after using pasteHTML method? -


I replace the selected text with the pasteHTML method (HTML paste the text in the given text category, in which any The previous text and HTML elements are replaced by the category). In Internet Explorer

  var ran = Editor.selection.createRange (); Ran.paste HTML ('& lt; span style = "font-size: 20px;" & gt; example & lt; / span & gt;');  

After the text is replaced, the selection disappears. How to highlight the previous selection (text) again? Thanks

Paste HTML will delete the existing selection from the document, so I suppose You want to select the span that you have changed it. To do this, add an ID for the period, select TextRange by wrapping its text and choose it, as follows:

  var ran = Editor.selection.createRange (); Ran.paste HTML ('& lt; span style = "font-size: 20px;" id = "a_random_unique_id"> example ;); Var spanRange = ran.duplicate (); SpanRange.moveToElementText (document.getElementById ("a_random_unique_id")); SpanRange.select ();  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -