4

I have a script that gets executed by an onclick, but it doesn't work when I use a image, only a button works. You can see the example at http://thomaswd.com/maze. Click on the "left" button then the down button, and they both work. But the right arrow doesn't work, for some reason. Please help. Thanks!

Thomas Lai
  • 317
  • 1
  • 6
  • 15

4 Answers4

2

Strange, I don't understand why right() is not working but works if I rename the function to different name.

Demo: http://jsfiddle.net/5b3Ez/

Rename right() function to a different name and Hope that helps for now.

Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70
2

Change the id from 'right' to something else. I am not entirely sure why this fails, but apparently within the html, since 'right' is the id, it hides the right() function.

In Chrome debugger, I changed the id to 'r' and the button works, although it is huge because of the css not matching anymore :)

As others noted, the 'up' and 'down' buttons work, and this is because their ids are 'top' and 'bottom'.

EDIT:

And here is an explanation, very strange issue :)

Community
  • 1
  • 1
Paul Hoenecke
  • 5,060
  • 1
  • 20
  • 20
1

I'm a bit confused as to why right doesn't work when up does under the same circumstance, but it seems that you can get it to work by binding via JavaScript (which you should really do anyway) instead of using onclick.

$("#right").on('click', right);
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
0

Instead of right(), just use window.right().

In that context, I tried:

console.log(this.right===right, this.right===window.right, right===window.right);

and it displays true false false, but in case of other arrows, it is false false true. The explanation pointed to by Paul Hoenecke points towards the problem.

Kaustubh Karkare
  • 1,083
  • 9
  • 25