Reputation:
I think I figured it out... see my comment. Sorry.
I have a JSON web service that is called on a certain keyup() event which retrieves some data based on the input. I would like to load an initial set of data before anything is typed. I'm trying to manually invoke the keyup() as stated in the documentation, but it doesn't seem to do anything.
$('#inputItemName').keyup(function () {
//perform query, display results
});
^^ works great when you type in the box
$('#inputItemName').keyup();
^^ called immediately after document ready function, doesn't seem to do anything.
Upvotes: 58
Views: 105070
Reputation:
I think I figured it out... I moved the function that calls the results higher up in the script tag than the keyup()
invocation and now it works.
Upvotes: 2
Reputation: 4278
Try this:
$('#inputItemName').bind('keyup',function() {
//stuff
});
Upvotes: -3
Reputation: 11088
Try trigger function.
$('#inputItemName').trigger('keyup');
http://api.jquery.com/trigger/
Upvotes: 7
Reputation: 8699
Works fine for me: http://jsfiddle.net/radu/gD5WL/
$('#test').keyup(function () {
console.log('hello');
});
$('#test').keyup();
The keyup
event is getting called on page load.
Upvotes: 90
Reputation: 17472
You are missing a #
in selector...
try with hash...
$('#inputItemName').keyup();
Upvotes: 3
Reputation: 13200
You're missing the hash marker for the id in the second one:
$('#inputItemName').keyup();
Upvotes: 1