Bug Tracker

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13721 closed bug (fixed)

remove(":nth-child(1)") works differently than filter(":nth-child(1)").remove()

Reported by: nicofrand@… Owned by: dmethvin
Priority: low Milestone: 1.10
Component: manipulation Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

First, a jsFiddle example : http://jsfiddle.net/Jjym7/7/. In this jsFiddle, only the first child of each list should be removed.

According to the remove documentation, the remove method should do the same thing than applying first the filter method and then the remove method.

I think this is due to the fact that the remove function applies jQuery.filter in a loop for each element in the object so that each element becomes the first (:nth-child(1)) when the filter is called.

Line 5986 from http://code.jquery.com/jquery-1.9.1.js.

Change History (4)

comment:1 Changed 5 years ago by dmethvin

Component: unfiledmanipulation
Priority: undecidedlow
Status: newopen

Agreed. It *seems* like moving the filter outside the loop and removing that set would be better anyway ... so it must be a trap of some kind.

comment:2 Changed 5 years ago by dmethvin

Owner: set to dmethvin
Status: openassigned

comment:3 Changed 5 years ago by Dave Methvin

Resolution: fixed
Status: assignedclosed

Fix #13721. Filter before .remove() loop so positionals work. Close gh-1221.

Changeset: 1b610266502490eab42a0b9ddfac2f93da0b0fe1

comment:4 Changed 5 years ago by dmethvin

Milestone: None1.10

Fixed in master/2.0 per the above commit and cherry-picked into 1.x at https://github.com/jquery/jquery/commit/f7a378e6b7b4599930a9bd97bd30ff4855498a5f

Note: See TracTickets for help on using tickets.