manually trigger jquery keyup?

Jquery

Jquery Problem Overview


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.

Jquery Solutions


Solution 1 - Jquery

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.

Solution 2 - Jquery

$('#inputItemName').trigger('keyup');

Solution 3 - Jquery

You are missing a # in selector... try with hash...

$('#inputItemName').keyup();

Solution 4 - Jquery

Try trigger function.

$('#inputItemName').trigger('keyup');

http://api.jquery.com/trigger/

Solution 5 - Jquery

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.

Solution 6 - Jquery

You're missing the hash marker for the id in the second one:

$('#inputItemName').keyup();

Solution 7 - Jquery

Try this:

$('#inputItemName').bind('keyup',function() {
    //stuff
});

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTHE JOATMONView Question on Stackoverflow
Solution 1 - JqueryRaduView Answer on Stackoverflow
Solution 2 - JquerySenad MeškinView Answer on Stackoverflow
Solution 3 - JqueryTeja KantamneniView Answer on Stackoverflow
Solution 4 - JqueryPiotr PerakView Answer on Stackoverflow
Solution 5 - JqueryTHE JOATMONView Answer on Stackoverflow
Solution 6 - JqueryglorthoView Answer on Stackoverflow
Solution 7 - JqueryrichsoniView Answer on Stackoverflow