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

  • Home
  • SEARCH
  • 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 9247593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:46:06+00:00 2026-06-18T09:46:06+00:00

Was trying to make a minesweeper in javascript and ran into this problem… I

  • 0

Was trying to make a minesweeper in javascript and ran into this problem…

I created a table and each td is a “box” with either a mine or nothing(Currently) in it.
After I click on a box, the javascript should change the onclick from “clicked(this.id)” to an alert that says “NOPE”(made an alert just to test if something was happening), but what happends is:

  1. I click on “box 1”, it reveals what’s there (bomb or nothing)
  2. I click on it again, this time I get an alert “NOPE” – which means the onclick has changed. Good!
  3. I click on “box 2”, it reveals what’s there (bomb or nothing)
  4. I click on it again, this time I get an alert “NOPE” – which means this onclick has changed too!
  5. I click on “box 1” again. The clicked(this.id) runs again. (This is shown because I added a counter for each time the function runs)

For some reason, the onclick returns to its original value (clicked(this.id))..

I made a test page, a table with 2 td’s and the same thought in mind(change onclick value after it’s clicked) and it works.. I have no idea how to fix this…

The test.html that does work:
http://pastebin.com/62ayRJps

The HTML from the site that doesn’t work as intended:
http://pastebin.com/SZ6NU8j9

And the Javascript from the site that doesn’t work as intended:
http://pastebin.com/bevJHNLc

  • 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-18T09:46:08+00:00Added an answer on June 18, 2026 at 9:46 am

    Your click event handlers are being reset because of this line in clicked(id):

    document.getElementById("minesweeper").innerHTML += ammountClicked+" - "
    

    Each table cell has a onclick='clicked(this.id);' attribute in its HTML. When you assign your test function tst to the table cell DOM object, you’re setting the onclick property of the DOM object, but that doesn’t change the onclick attribute of the HTML. (Yes, it’s confusing.)

    In the line of code above, the browser reads the innerHTML from the minesweeper div (which has the original onclick attributes), concatenates it with another string, then reassigns the result back to the minesweeper div. This wipes out the original contents of the div and replaces it with the new HTML (a table where every cell has the original onclick attribute).


    If you want to have a message area, I suggest setting innerHTML on another element: Demo

    In the demo, I changed line 49 (adding a span):

    print += "</table><span id='message'></span>";
    

    and line 107 (assigning the text to the span):

    document.getElementById("message").innerHTML += ammountClicked+" - ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make simple minesweeper game in python, but have one problem. I have
Hello I am trying make a browser cache experiment. like this <head> <script type=text/javascript
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to make the infamous checkall checkbox for dynamically created rows from a MySQL
Trying to make a simple number clicker control for BlackBerry 6/7, like this: At
im trying make one replace in string from a array but this dont work
I'm trying make an input box pop up asking the user for a password
I'm trying to make a vista minesweeper clone. Right now my uncover algorithm is
I'm trying make a JFileChooser for selecting a folder. In this FileChooser, I'd like
Trying to make a Grid Like this using java and I'm assuming a 2d

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.