Skip to content Skip to sidebar Skip to footer

Detecting A Keypress Within A Form?

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 prin

Solution 1:

You forgot the . in the class selector:

$(document).on("keypress", ".filterinput", function(e) {
//                          ^ this . indicates that it's a class selectorconsole.log("press detected");
});

Solution 2:

your selector should be .filterinput

Solution 3:

You're missing the period . in your selector that signifies "look for a class":

$(document).on("keypress",".filterinput",function(e) {
//                         ^ period

Solution 4:

Try this code

$(".filterinput").keypress(function(e)
    {
        console.log("press detected");
    });

    <formclass="filterform"><inputclass="filterinput"type="text"></form>

Post a Comment for "Detecting A Keypress Within A Form?"