faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

56 of 117 people (48%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How do I find the caret position in an IE5.5+ ContentEditable DIV layer?

Apr 11th, 2002 10:39
Beiker Beikersson, Dave Clark,


In this example the cursor position is saved "onkeyup".
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>::::</title>
<script language="javascript">
	var cursorPos;
	function saveCursorPos(){
		cursorPos=document.selection.createRange().duplicate();
	}
	function paste(str){
			if(str) cursorPos.pasteHTML(str);
	}
//-->
</script>
</head>
<body bgcolor="#ffffff">
<a href="javascript:void(0);" onclick="paste('<b>new text</b>');return 
false;">test</a>
<div id="test"  contenteditable onkeyup="saveCursorPos();">Beiker was a 
baker once.</div>
</body>
</html>