gandjyar
gandjyar

Reputation: 1203

Jquery on click function is not working for img in IE 8

I've got a bunch of radio buttons and images. I'm trying to make the images clickable because I would like to use the images in place of the radio buttons. I'm using CSS to hide the radio buttons and in Firefox this script works great, but it doesn't work at all in IE (nothing happens when you click on the image). Any ideas of what I'm doing wrong?

$(document).ready(function() {
    $('img').click(function() {
        $(this).next().click();
    });
});​

I'm using jquery 1.6.1.

I do not want to change the image after it is clicked, I only want to be able to click the image and use it in place of the radio box. I am able to click the image in Firefox, but not in IE.

I've tried changing the script to this and it works in IE without any problems:

$(document).ready(function() {
$('img').click(function(){
alert("Show me");
});
});

Upvotes: 0

Views: 577

Answers (1)

Isaac Fife
Isaac Fife

Reputation: 1689

http://jsfiddle.net/uJ9tK/1/

The code you have shown us is correct. Whether you hide the radio buttons or not, they are being clicked. Whatever you do when the radio buttons are clicked is the part that is broken. I tested this in IE7, 8, 9 and compatibility mode.

Upvotes: 1

Related Questions