mare
mare

Reputation: 13083

jquery selector not working in IE8

This code results in an error at second line ($('boxes div.box'))

<script type="text/javascript">

    $(document).ready(function () {
        boxes = $('#boxes div.box');
        images = $('#images > div');
        boxes.each(function (idx) {
            $(this).data('image', images.eq(idx));
        }).hover(
            function () {
                boxes.removeClass('active');
                images.removeClass('active');
                $(this).addClass('active');
                $(this).data('image').addClass('active');
            });
    });

</script>

The error is "Object doesn't support this property or method". The same page works fine in Firefox and Chrome.

Anyone?

Upvotes: 0

Views: 4272

Answers (1)

BoltClock
BoltClock

Reputation: 723638

You need to declare variables with the var keyword, otherwise IE has no idea where they're coming from and so will just break:

var boxes = $('#boxes div.box');
var images = $('#images > div');

Upvotes: 10

Related Questions