I have a basic textarea:
<textarea id='text_comment'></div>
I have this function:
$('#text_comment').live('keypress', function() {
setTimeout(function() {
string = $(this).val();
alert(string);
}, 500);
});
It should alert the value that is in the textarea, but it alerts nothing.
I would like it to get the value of the textarea after 500ms, but it doesn’t seem to set the variable if it is inside of the setTimeout function.
context becomes
window‘s sincesetTimeoutis a method ofwindow.if you save a reference to the el in this manner you can rely on it instead of
thisAnd also, you can just use
el.valuesince theres no need to wrap it in jQuery and do the exact same thing internally by.val()