开发者

jquery selector not working in IE8

开发者 https://www.devze.com 2023-01-19 03:36 出处:网络
This code results in an error at second line ($(\'boxes div.box\')) <script type=\"text/javascript\">

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 开发者_JAVA百科support this property or method". The same page works fine in Firefox and Chrome.

Anyone?


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');
0

精彩评论

暂无评论...
验证码 换一张
取 消