最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery selector not working in IE8 - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Apr 26, 2012 at 4:23 BoltClock 725k165 gold badges1.4k silver badges1.4k bronze badges asked Oct 4, 2010 at 18:11 maremare 13.1k24 gold badges106 silver badges193 bronze badges 2
  • What do your <script> tags look like, where you're including jQuery? – Nick Craver Commented Oct 4, 2010 at 18:14
  • 1 That's an assumption in many cases...if you knew the source of the problem why would you be asking? Script includes cause this, as slight differences will affect only IE, never assume! – Nick Craver Commented Oct 4, 2010 at 18:21
Add a ment  | 

1 Answer 1

Reset to default 10

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

var boxes = $('#boxes div.box');
var images = $('#images > div');
发布评论

评论列表(0)

  1. 暂无评论