I would just like to have an editable div that acts like a textarea that is given focus on page load (i.e. the blinking cursor is visible and typing shows up in the div without having to select the div with the mouse). I've tried calling focus() on the editable div, but that doesn't work.
views:
202answers:
1
+1
A:
I'm not sure it's possible to control the cursor, but you can simply focus the element:
function initPage() {
var elEd = document.getElementById('editor');
elEd.contentEditable=true;
elEd.focus();
}
In Chrome, if your element with ID editor has any content then the whole content will be selected. In Firefox you don't see a cursor, but if you type after loading the page it will appear in the element. Simple example here.
robertc
2010-05-22 17:52:13