Onclick image instead of button on click?

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

+3


source to share


4 answers


Change the identifier from "right" to something else. I'm not really sure why this fails, but apparently inside the html, since "right" is the id, it hides the function right()

.

In Chrome debugger, I changed the id to "r" and the button works, although it is huge due to the fact that css no longer fits :)

As others have pointed out, the up and down buttons work, and this is because their identifiers are “top” and “bottom”.



EDIT:

And here's the description, a very strange problem :)

+2


source


Strange, I don't understand why it right()

doesn't work, but it works if you rename the function to a different name.

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



Rename the right()

function to a different name and hope this helps now.

+2


source


I'm a little confused as to why it right

doesn't work when up

it does under the same circumstances, but it seems like you can get it to work by binding with JavaScript (which you really should be doing anyway) instead of using onclick

.

$("#right").on('click', right);

      

+1


source


Instead, right()

just use window.right()

.

In this context, I tried:

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

      

and displays true false false

, but in the case of other arrows it is false false true

. The explanation pointed out by Pavel Honecke points to a problem.

0


source







All Articles