Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:57:48+00:00 2026-06-15T22:57:48+00:00

I need to detect when someone hits enter in text inputs with a specific

  • 0

I need to detect when someone hits “enter” in text inputs with a specific class.

My jQuery is as follows:

$('input.large').keypress(function (e) {
    if(e.which ==13)
        console.log("pressed enter");
});

My HTML is something like this:

<tr><td> Personal Name </td></tr>
<tr><td> <input type='text' class='large'> </td></tr>

<tr><td> Email</td></tr>
<tr><td> <input type='text' class='large'> </td></tr>

When I’ve given the fields IDs and tried $('#elementid').keypress it worked. But this isn’t working. I get no console output. What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:57:50+00:00Added an answer on June 15, 2026 at 10:57 pm

    You can use live (.on()) events in document with keydown (I think this is better). It’ll allow you detect keydown in current and future elements that matches with a selector.

    HTML:

    <strong>Personal Name</strong>
    <input type='text' class='large' /><br />
    
    <strong>Email</strong>
    <input type='text' class='large' />
    ​
    

    JS (jQuery 1.7+):

    Note: .which, .code, .charCode and .keyCode is now deprecated. Use the following new solution:

    jQuery(document).on('keydown', 'input.large', function(ev) {
        if(ev.key === 'Enter') {
            // Will change backgroundColor to blue as example
            this.style.backgroundColor = '#EFF';
    
            // Avoid form submit
            return false;
        }
    });
    

    jsFiddle: http://jsfiddle.net/david_proweb/fjgvhubn/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a quick and dirty way to detect media query support using jquery.
I need to use a function in PHP that detect a delimiter of a
I want to detect words in text, i.e. I need to know which characters
I'm new to JS and I need to detect whenever someone enters to my
In ASP.net Webforms how do you detect which Textbox someone pressed enter? Please no
I need to detect all the red pixels in an image using Java. What
I need to detect IE7 (and IE6) using the user agent string: I have
I need to detect android device orientation change without playing manually with sensor data,
I need to detect which version of SQL I am dealing with to perorm
I need to detect and eval the Javascript code contained in a string. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.