weird problem with .val on input and .append in jquery
<p>I have this code in jquery: </p>

<pre><code>$(document).ready(function () {

$("#main-edit").click( function() {
var cursorExists = $("#cursor").length;
if (!cursorExists){
   $("#cursor-start").append("&lt;input type='text' id = 'cursor' /&gt;");
   $("#cursor").markCursor();
}
   if (cursorExists){
    $("#cursor").markCursor();
}

});

jQuery.fn.enterText = function(){
if( $("#cursor").val() ){
    var character = $("#cursor").val();
    $("#cursor").val("");
    return this.append("&lt;span&gt;"+character+"&lt;/span&gt;");
}

};

jQuery.fn.markCursor = function(){
    $(this).focus();
   $(this).keydown(function() {
  $("#cursor-start").enterText();
});
};

});
</code></pre>

<p>My problem is in the enterText function. On the keydown function, I get the value of the input, store it, clear the input, and append the stored value. But when I type something like "foo"....I get "fo".....when I type "food"....I get "foo". So its not getting the last entered value for some reason.</p>
