开发者

jQuery child and ancestor selector not working in IE 8

In jQuery, child selectors supposedly work in IE 7+, but a particular selector path is not working for me in IE 8. Given the following code:

<html>
  <head>
    <script type="text/javascript" src="jquery-min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        $('.a > div a').text("Found!");
      });
    </script>
  </head>
  <body>
    <div class="a">
      <div>
        <div>
          <a href="#">Not Found</a>
        </div>
      </div>
    </div>
  </body>
</html>

"Not Found" remains in the <a/> element. If I remove one of the divs, the selector doe开发者_如何学Cs work. Is my selector incorrect, or is this a known or discovered jQuery bug? We're using version 1.4.1, but I just verified the same behavior occurs in jQuery 1.4.4.


Unfortunatly, I don't have a windows machine right now. But if it really is not working in IE8 you probably should fill a bug.

Anyway, to avoid the selector you can always use

$('.a > div').find('a').text('Found!');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜