Define cursor on element
Posted
by sanceray3
on Stack Overflow
See other posts from Stack Overflow
or by sanceray3
Published on 2010-03-09T13:51:40Z
Indexed on
2010/03/14
1:45 UTC
Read the original article
Hit count: 286
Hi all,
I try to explain my problem.
I have a <div contenteditable="true" id="my_editeur>
, where I have defined a keypress “event” which allow me to add a ‘p’ when the user clicks on “enter”.
It functions well, but I would like define the cursor on this new ‘p’ element, because currently my cursor stays on the first 'p' element.
I have tried to use jquery focus function but it seems that we can’t use this function for ‘p’ elements.
Do you know how I can do to solve my problem?
Thanks very much for your help.
My code :
$('#my_editeur').keypress(function(e){
if(e.keyCode == 13) {
e.preventDefault();
$(this).append('<p ><br /></p>');
}
});
© Stack Overflow or respective owner