jQuery debounce, way to pass the element along to the function?
HTML
<input class="list_item_title mini" name="list_item[title]" size="30" type="text" value="What happens when a user creates a new item?">
JS:
function text_2(e) {
开发者_StackOverflow console.log(e.val());
};
$(function() {
$('input.list_item_title').keyup( $.debounce( 250, text_2 ) );
});
e.val() currently doesn't work. how can I pass the input along so I can get the value?
Thanks
e
is a reference to the event object [docs], not the input
element.
You can get a reference to the input
element using event.currentTarget
[docs].
After the having a look at the source code, you should also be able to access the element with this
(like in any other event handler), so the following should work:
function text_2(e) {
console.log($(this).val());
};
console.log($(e.target).val());
精彩评论