Bug Tracker

Modify

Ticket #4621 (closed bug: invalid)

Opened 4 years ago

Last modified 2 years ago

filter("...:first") expands original selector

Reported by: zaphod_41 Owned by: zaphod_41
Priority: major Milestone: 1.3.2
Component: selector Version: 1.3.2
Keywords: filter() Cc:
Blocking: Blocked by:

Description

I create a selector, then filter() that selector and put a length check on the end to see if anything matches, eg

var jSelector = $("foo"); if (jSelector.filter("bar").length > 0) ...

Which works fine. I was hoping I could avoid jQuery filtering the entire selector, by sticking a ":first" on the end of the filter (ie "hey, stop filtering on the first one you find"), eg

if (jSelector.filter("bar:first").length > 0) ...

What happened is that, even though the original selector found no matches (length ==0), the added filter suddenly returned a match (length == 1).

var jNewRows =

$("#table tr:has(td[id$=status] :contains('New'))");

--- console.log(jNewRows) sez []

var a =

jNewRows.filter("td[id$=volume] input[value]");

--- console.log(a) sez []

var b =

jNewRows.filter("td[id$=volume] input[value]:first");

--- console.log(b) sez [input#...] (single entry)

John Finlay ThoughtWorks (403-613-7008)

Change History

comment:1 Changed 3 years ago by dmethvin

  • Owner changed from john to zaphod_41
  • Status changed from new to pending

I was going to try and create a test case myself but the markup seems like it may be complext. Please create a complete jsfiddle case with the html.

comment:2 Changed 2 years ago by trac-o-bot

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

Automatically closed due to 14 days of inactivity.

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.