Bug Tracker

Modify

Ticket #2847 (closed bug: fixed)

Opened 5 years ago

Last modified 15 months ago

jQuery :first-child selector does not work in IE if comment precedes element

Reported by: westonruter Owned by: john
Priority: major Milestone: 1.4
Component: selector Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

In MEIE 6/7/8b1, the :first-child selector does not work if a comment is the first child; it does not work using either pure CSS nor using the jQuery selector engine. Both, however, work in Firefox and Safari.

Test case:  http://weston.ruter.net/projects/test-cases/jquery-first-child-bug/

Attachments

2847.html Download (6.4 KB) - added by nathanhammond 5 years ago.
In depth test case.
2847.diff Download (795 bytes) - added by nathanhammond 5 years ago.
Patch

Change History

comment:1 Changed 5 years ago by pr

The problem occurs because the first node returned for IE is the comment node. Here is my attempt at fixing it. (checked in IE6/7 and FF2/3).

"first-child": function(a){
  var isFirst = false;
  $.each(a.parentNode.getElementsByTagName("*"), function() {
    // check if the first non-comment node is same as the node.
    return (this.tagName === '!') || ((isFirst = (this == a)) && false);    
  });
  return isFirst;
}

Changed 5 years ago by nathanhammond

In depth test case.

comment:2 Changed 5 years ago by nathanhammon

I've done a much more in-depth test case and determined that this is the only one of the similar selectors that exhibits this bug. It appears that .getElementsByTagName("*") returns comment nodes in IE. I'm working on a patch.

Changed 5 years ago by nathanhammond

Patch

comment:3 Changed 5 years ago by nathanhammon

To fix this we're going to have to go slower and longer. A more clever patch might be better than the one I've just posted for review.

comment:4 Changed 3 years ago by john

  • Owner set to john
  • Component changed from core to selector

comment:5 Changed 3 years ago by john

  • Version changed from 1.2.3 to 1.3.2
  • Milestone changed from 1.2.4 to 1.4

comment:6 Changed 3 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to fixed

This appears to have been fixed in 1.3.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.