Benubird
Benubird

Reputation: 19487

onclick not working in internet explorer 7

I have the following code on a webpage:

<DIV style="TEXT-ALIGN: center">
<A style="CURSOR: auto" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='auto'" onclick="alert('0: 272ec6651cb6d320579205b7a250a14920708a41');">[Back To List]</A>
<A onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='auto'" onclick="alert('1: 20');">[View Comments]</A>
</DIV>

The first link works, the second one doesn't. By works, I mean that the pointer changes on mouseover, and clicking it triggers the alert message. The second link, the mouse doesn't change, and clicking it does nothing. What have I done wrong here? How do I make this work?

Also note, that this works fine in firefox, google chrome, and internet explorer 8 - it's only internet explorer 7 and below that have a problem with it, but I do need to support them.

Edit: To clarify, nothing about the second link is working - it's not just the javascript, the mouseover is also not changing the mouse pointer like it does for the first. There's obviously something about the first link that is causing ie to not process the second properly, but I can't see what it could be.

Upvotes: 0

Views: 5058

Answers (4)

Benubird
Benubird

Reputation: 19487

I found a fix for it. It's not actually visible in the original question (sorry!) but the second link ended with </A></DIV>. I added a space, to make it </A> </DIV> and it works now.

I've pretty much given up on internet explorer making sense, but this is exceptionally bewildering. So if anyone can tell me why I needed that extra space I'd appreciate it (and mark your answer correct).

Upvotes: 0

Michael Laffargue
Michael Laffargue

Reputation: 10294

I copy/paste your code in my page and opened it with IE7, no problem at all with cursors nor links.

I tried with/without Quircks mode and both worked. You may have something else in the page that is interfering?

My IE version : 7.0.6001.18000

Upvotes: 0

Adam Ayres
Adam Ayres

Reputation: 8900

You might try prefixing the onclick with javascript: like so:

<A onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='auto'" onclick="javascript:alert('1: 20');">[View Comments]</A>

Could it be possible that your IE7 is blocking alerts? Maybe change it from an alert to some user defined function or evening change the cursor style as you have done for the mouseover just to test.

Upvotes: 0

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21366

try using developer tools in IE to find your second link's position in IE7. May be it's not in where you think it should be.

Upvotes: 1

Related Questions