Bug Tracker

Modify

Ticket #4945 (closed enhancement: duplicate)

Opened 5 years ago

Last modified 5 years ago

Enhancing "closest" method for delegation

Reported by: mike.helgeson Owned by:
Priority: minor Milestone: 1.4
Component: core Version: 1.3.2
Keywords: delegation Cc:
Blocking: Blocked by:

Description

I propose adding a second argument to the "closest" method that will act as the end point for searching up the document tree. It can behave just like the "context" argument in the jQuery mother function. It will optimize the performance of a common pattern I have seen in my own code since the addition of this method. The new usage could be as follows:

$("table").bind("click",function( event ){

var $td = $( event.target ).closest("td", event.currentTarget );

});

Because I bound the handler to "table" I do not want to search any higher than that element for selector matches. Furthermore, if there was a selector match outside of the containing element, it could potentially and accidentally be matched.

I have attached the modified method. It is a very small change, and makes "closest" even more powerful for advanced developers.

Attachments

jquery.closest.js Download (460 bytes) - added by mike.helgeson 5 years ago.

Change History

Changed 5 years ago by mike.helgeson

comment:1 Changed 5 years ago by mike.helgeson

comment:2 Changed 5 years ago by joern

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

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.