Bug Tracker

Modify

Ticket #3746 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

Unexpected return from .contains when using ':first-child' selector

Reported by: culyun Owned by: john
Priority: minor Milestone: 1.3
Component: selector Version: 1.2.6
Keywords: ':first-child', ':first', 'contains', 'children' Cc: culyun
Blocking: Blocked by:

Description

Environment

IE 6.0.2900.2180.xpsp_sp2_gdr.080814-1233 FF 2.0.0.32 Opera 9.62

Example

jQuery(document).ready(function() {

var html = ; html += '<form class="the-form">'; html += 'silly text'; html += '<img class="silly-img" src="potato.jpg"/>'; html += '</form>';

create an unattached dom wrapped inside a jquery

var dom = $(document.createElement('div')).html(html); var form = dom.find('.the-form');

As I read the documentation the output from the use of ':first' and 'first-child' selectors, should be identical in the case of a trivial (single-element) selection set

var firstElem = form.children(':first'); ok, returns silly-img var firstNode = form.contents(':first'); ok, returns 'silly text'

firstElem = form.children(':first-child'); ok, returns silly-img firstNode = form.contents(':first-child'); fail, returns silly-img. should return 'silly text'

}

Attachments

jQuery_1_2_6_contains_returns_incorrect_result.js Download (865 bytes) - added by culyun 4 years ago.

Change History

Changed 4 years ago by culyun

comment:1 Changed 4 years ago by flesler

  • Cc culyun added
  • Owner changed from flesler to john
  • Component changed from unfilled to selector

comment:2 Changed 4 years ago by john

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

:first-child only matches elements, not text nodes - this is expected with the CSS Selector specification.

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.