Is it possible to restore the selection when the html structure in a DIV is changed (text is the same)

313 views
Skip to first unread message

Jeffrey Zhao

unread,
Mar 15, 2012, 6:57:18 AM3/15/12
to rangy
Hi guys,

I've written a simple test with rangy's selection save/restore
function:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Hello</title>
<script type="text/javascript" src="rangy-core.js"></script>
<script type="text/javascript" src="rangy-
selectionsaverestore.js"></script>
</head>
<body>

<div id="show" class="code" contenteditable="true"><span
style="color:red">12345</span>12345</div>

<script type="text/javascript">
window.setTimeout(function () {
var s = rangy.saveSelection();
var show = document.getElementById("show");
show.innerHTML = "1234512345";
rangy.restoreSelection(s);
}, 5000)
</script>

</body>
</html>

Basicly I have a div with colored text, and at some time I want to
replace the content with plain text (or some other html structure with
the same text). I used the code above to text the scenario but find
there's an error said: "Rangy warning: Module SaveRestore: Marker
element has been removed. Cannot restore selection."

Does rangy support the feature I mentioned above? If yes, how should I
use it? If no, what should I do to implement that?

Thanks.

- Jeff

Tim Down

unread,
Mar 15, 2012, 10:33:40 AM3/15/12
to ra...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages