Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

manually trigger jquery keyup?

Tags:

jquery

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.

like image 1000
THE JOATMON Avatar asked Jun 28 '11 19:06

THE JOATMON


People also ask

How do you trigger a Keyup event?

The keyup event occurs when a keyboard key is released. The keyup() method triggers the keyup event, or attaches a function to run when a keyup event occurs. Tip: Use the event. which property to return which key was pressed.

What is Keyup and Keydown in jQuery?

keyup(): Event fired when a key is released on the keyboard. keydown(): Event fired when a key is pressed on the keyboard. keypress:() Event fired when a key is pressed on the keyboard.


2 Answers

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.

like image 157
Radu Avatar answered Sep 21 '22 18:09

Radu


$('#inputItemName').trigger('keyup'); 
like image 35
Senad Meškin Avatar answered Sep 23 '22 18:09

Senad Meškin