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 6123971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:04:44+00:00 2026-05-23T16:04:44+00:00

I know that for handling keyboard events in an input field you can use:

  • 0

I know that for handling keyboard events in an input field you can use:

$('input').keyup(function(e){
var code = e.keyCode // and 13 is the keyCode for Enter
});

But, now, I have some div and li elements, and I don’t have a form element, and none of my elements are considered to be form elements and none of them accept focus or tab and stuff like that.

But now I need to handle the keyup (or keydown, or keypress, doesn’t matter) event in a div element. I tried:

$('div#modal').keyup(function(e){
   if (e.keyCode == 13)
   {
      $('#next').click(); // Mimicking mouse click to go to the next level.
   }
});

But the problem is, it doesn’t work.
What should I do?

  • 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-05-23T16:04:45+00:00Added an answer on May 23, 2026 at 4:04 pm

    A div by default cannot be given focus. However, you can change that by adding a tabindex attribute to the div:

    <div tabindex="0" id="example"></div>
    

    You can then give the div focus, and also blur it with the hover event:

    $("#example").hover(function() {
        this.focus();
    }, function() {
        this.blur();
    }).keydown(function(e) {
        alert(e.keyCode);
    });
    

    When the div has focus, it will accept keyboard events. You can see an example of this working here.

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

Sidebar

Related Questions

We all know that you can overload a function according to the parameters: int
i know that there is some rules and standards in css handling but i
I know from wikipedia for example that exception handling is used in an application
I know that when I use range([start], stop[, step]) or slice([start], stop[, step]) ,
I know that this line of code will make the cell text-wrap: $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true); 'D1'
I know that I can hijack a form by showing a login form in
I know that general or across the board exception handling is a big no-no,
Does anyone know a way to display code in Microsoft Word documents that preserves
Is there a set of open standards technologies that I can use to achieve
I know that that on can have a class declaration in a method of

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.