I have this code :
jQuery.fn.enterText = function(e){
var $cursor = $("#cursor");
if (e.keyCode == 39){
e.preventDefault();
$cursor.val("");
var nextChar = $cursor.next();
$cursor.after(nextChar);
}
};
Im trying to move the #cursor to the right but it seems the browser does not allow it….the left arrow key works :
if (e.keyCode == 37){
$cursor.val("");
var previousChar = $cursor.prev();
$cursor.after(previousChar);
}
You should be using
beforeinstead of after:http://jsfiddle.net/Gq5HZ/1/
You are trying to add the element which is after the cursor, after the cursor… it’s already there.