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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:07:59+00:00 2026-05-22T16:07:59+00:00

I have 5 click-able div tags, the div’s display a yellow square with a

  • 0

I have 5 click-able div tags, the div’s display a yellow square with a number in. When the user clicks a square, the colour of the square changes to indicate that the clicked square is the ”active” square (This part works fine). Then the user should be able to press a number. When the number is pressed, the number displayed in the div should change to the number they have pressed!

BUT… It doesn’t work! as a div attribute, I have onkeypress=”(function to change innerHTML of the tag)”.

For testing purposes I wrote onkeypress=”alert(‘key’);” as a div attribute to see if it was my javascript function, or the onKeyPress itself! but the Alert wont even display!

I tried putting the onKeyPress alert in the body tag, and it worked fine. its just the div! I also tried pressing a key before I clicked on the div and after I clicked on the div!

I also tried onkeydown and onkeyup!

I really cant see the problem! Code follows:

<html>
<head>
<style type="text/css">
#grid {
    position:absolute;
    padding: 0;
    border:0;
    width:370px;
    height:370px;
}
.box
{
    position:absolute;
    border: 2px solid Black;
    height: 50px;
    width: 50px;
    vertical-align: middle;
    text-align: center;
    background-color: yellow;
    font-size: xx-large;
    color:Navy;
    font-family: Arial;
    margin:10px;
    line-height:1.6;
}
.boxActive
{
    background-color:Aqua;
}
</style>

<script type="text/javascript>
function clicked(id) {
    reset();
    $(id).addClass('boxActive');
}
</script>

<script type="text/javascript" src="JQuery.js"></script>

</head>
<body>
    <div id="grid">
        <div id="cell_0_0" class="box" onclick="clicked(this);" onkeypress="alert('key');" style="top:0%;  left:0%; ">0</div>
        <div id="cell_0_1" class="box" onclick="clicked(this);" onkeypress="alert('key');" style="top:0%;  left:20%; ">0</div>
        <div id="cell_0_2" class="box" onclick="clicked(this);" onkeypress="alert('key');" style="top:0%;  left:40%; ">0</div>
        <div id="cell_0_3" class="box" onclick="clicked(this);" onkeypress="alert('key');" style="top:0%;  left:60%; ">0</div>
        <div id="cell_0_4" class="box" onclick="clicked(this);" onkeypress="alert('key');" style="top:0%;  left:80%; ">0</div>            
    </div>
</body>
</html>

Can anybody suggest how to fix this OR a method to change the innerHTML of the div Tags when a user clicks the div and presses a key!

Thankyou!!!

Alex

  • 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-22T16:08:00+00:00Added an answer on May 22, 2026 at 4:08 pm

    I came across a similar problem recently. I think what you need to do is enable your DIV to receive the focus. The answer to this question should help – essentially add a tabindex attribute to the DIV.

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

Sidebar

Related Questions

I want to make a div click-able and but inside this <div> i have
I have the following setup on 2 div tags: <div id='div1' style='position: absolute; z-index:
I have a div, and when you click on it, used toggle() and shows
I have click-able images in my html page that call a javascript function... however
Is there a way, in CSS, I can make an element click-through-able. I have
I have a jsFiddle setup to where you will be able to click on
If I have a div that is a 5x5 square or something. I want
I have quite a few section tags in a div with an overflow set
THis is what i currently have click = false; if click $(el).on('click', 'li', {})
I have 2 click handlers binded to an element like so: in the file

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.