Bug Tracker

Opened 14 years ago

Closed 14 years ago

#3746 closed bug (invalid)

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
Blocked by: Blocking:



IE 6.0.2900.2180.xpsp_sp2_gdr.080814-1233 FF Opera 9.62


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 (1)

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

Download all attachments as: .zip

Change History (3)

comment:1 Changed 14 years ago by flesler

Cc: culyun added
Component: unfilledselector
Owner: changed from flesler to john

comment:2 Changed 14 years ago by john

Resolution: invalid
Status: newclosed

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

Note: See TracTickets for help on using tickets.