I need some help with the jQuery focus function.
I have an input field and I would like to do something when Enter is pressed and the input field has focus.
HTML:
<form class="myform">
<ul>
<input class="inputfield" type="text">
</ul>
</form>
and jQuery:
$(document).keyup(function(event) {
if (event.keyCode == 13 && $(':input').is(':focus')) {
//do stuff here
}
});
the .is(‘:focus’) returns always false.
Does anyone know whats the problem here?
Thanks!
Why don’t you assign the keyup event directly to the input fields?