Vincenzo Lo Palo
Vincenzo Lo Palo

Reputation: 1381

click() jquery not works in IE8

I have this scenario:

<div class="nextMediumImg"></div>
<a class="next" rel="history" title="successiva" href="#4">
  <img src="images/next_image.png" width="13" height="27" alt="Successiva">
</a>

When I click div(class="nextMediumImg"), occurs event click in image (class="next")

this is jquery

    <script>
      $(document).ready(function () {
         $('.nextMediumImg').click(function () {
            $('.next img').click();
            });
         });
    </script>

This jquery works correctly in Chrome, Firefox but NOT in IE8. How can I solve this strange issue? Thanks in advance!

Upvotes: 2

Views: 481

Answers (2)

Murali Murugesan
Murali Murugesan

Reputation: 22619

It works in IE 8 with jQuery 1.10.1, I dont see any issue. Save this code as .html and open in IE 8.

If not work, then you should be using jQuery 2.X which has dropped a support for IE 8 :)

<html>
<head>
<style type="text/css">
.nextMediumImg{
    height:20px; width:50px; display:block; background-color:orange;
}
</style>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

<script type="text/javascript">
      $(document).ready(function () {
          $('.next img').click(function(){alert('yeah');});
          $('.nextMediumImg').click(function () {
            $('.next img').click();
            });
         });   
</script>
</head>
<body>
<div class="nextMediumImg"></div>
<a class="next" rel="history" title="successiva" href="#4">
  <img src="https://www.gravatar.com/avatar/4c05b8240ce655d4db67b1eb99f705d7?s=32&d=identicon&r=PG" width="13" height="27" alt="Successiva">
</a>

</body>
</html>

Upvotes: 1

q0re
q0re

Reputation: 1359

I think the problem is, you set the click to the img and not to the anchor.

Change

$('.next img').click();

to

$('.next').click();

should work.

Upvotes: 0

Related Questions