Reputation: 1505
I'm trying to get a web page detect user keypresses within a particular form (there is a function to be called on each keypress). However my code is not working (console never prints to the log):
$(document).on("keypress","filterinput",function(e) {
console.log("press detected");
});
<form class="filterform"><input class="filterinput" type="text"></form>
Upvotes: 0
Views: 266
Reputation: 4212
Try this code
$(".filterinput").keypress(function(e)
{
console.log("press detected");
});
<form class="filterform"><input class="filterinput" type="text"></form>
Upvotes: 0
Reputation: 46647
You're missing the period .
in your selector that signifies "look for a class":
$(document).on("keypress",".filterinput",function(e) {
// ^ period
Upvotes: 0
Reputation: 219938
You forgot the .
in the class selector:
$(document).on("keypress", ".filterinput", function(e) {
// ^ this . indicates that it's a class selector
console.log("press detected");
});
Upvotes: 2