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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:37:41+00:00 2026-05-10T16:37:41+00:00

I am building an application where I want to be able to click a

  • 0

I am building an application where I want to be able to click a rectangle represented by a DIV, and then use the keyboard to move that DIV by listing for keyboard events.

Rather than using an event listener for those keyboard events at the document level, can I listen for keyboard events at the DIV level, perhaps by giving it keyboard focus?

Here’s a simplified sample to illustrate the problem:

<html> <head> </head> <body>  <div id='outer' style='background-color:#eeeeee;padding:10px'> outer     <div id='inner' style='background-color:#bbbbbb;width:50%;margin:10px;padding:10px;'>    want to be able to focus this element and pick up keypresses    </div> </div>  <script language='Javascript'>  function onClick() {     document.getElementById('inner').innerHTML='clicked';     document.getElementById('inner').focus();  }  //this handler is never called function onKeypressDiv() {     document.getElementById('inner').innerHTML='keypress on div'; }  function onKeypressDoc() {     document.getElementById('inner').innerHTML='keypress on doc'; }  //install event handlers document.getElementById('inner').addEventListener('click', onClick, false); document.getElementById('inner').addEventListener('keypress', onKeypressDiv, false); document.addEventListener('keypress', onKeypressDoc, false);  </script>  </body> </html> 

On clicking the inner DIV I try to give it focus, but subsequent keyboard events are always picked up at the document level, not my DIV level event listener.

Do I simply need to implement an application-specific notion of keyboard focus?

I should add I only need this to work in Firefox.

  • 1 1 Answer
  • 2 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. 2026-05-10T16:37:41+00:00Added an answer on May 10, 2026 at 4:37 pm

    Sorted – I added tabindex attribute to the target DIV, which causes it to pick up keyboard events, for example

    <div id='inner' tabindex='0'>     this div can now have focus and receive keyboard events </div> 

    Information gleaned from http://www.w3.org/WAI/GL/WCAG20/WD-WCAG20-TECHS/SCR29.html

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

Sidebar

Related Questions

I'm building an as3 only web application and want to be able to include
I am building a Ruby on Rails application and I want to be able
If I'm building an application that will have over 30 models, and I want
I'm building a web application and eventually would want to use Yii framework. But
I'm working on building a Silverlight application whereas we want to be able to
I'm building a desktop application with Castle ActiveRecord and want to be able to
I'm building a simple Todo List application where I want to be able to
I'm building a web application wherein I want my users to be able to
I'm building a POS application, and I want the end user to be able
I'm building an application in Cocoa and I want to be able to let

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.