I was wondering how you can do .keyup()
and .click()
for the same #id
?
i.e. essentially I want to validate the #id
when both the user attempts to hit enter or hits the #search
button.
Thanks alot
The keyup() is an inbuilt method in jQuery which is used to trigger the keyup event whenever User releases a key from the keyboard. So, Using keyup() method we can detect if any key is released from the keyboard. Syntax: $(selector).keyup(function) Here selector is the selected element.
keyup / keydown seem to only work on elements that are present at document. ready . If you are triggering your event from elements that were altered or injected post pageload, these events will not fire.
The keyup event is fired when a key is released. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .
$('#foo').bind('click keyup', function(event) {
...
You'll have to add some logic, as the event type changes, but it should work with enough if
blocks.
Well you can do:
$(document).keydown(function(objEvent) {
if (objEvent.keyCode == 13) { //clicked enter
$('#search').click(); //do click
}
})
$("#search").click(function(e){/*click fn*/})
Will run the click on enter press
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With