Skip to main content

Bug Tracker

Side navigation

Ticket #4539: closest-context.patch
File closest-context.patch, 0.6 KB (added by jollytoad, April 16, 2009 08:05AM UTC)

Restrict closest to search only within the jQuery context

Index: src/traversing.js
===================================================================
--- src/traversing.js	(revision 6308)
+++ src/traversing.js	(working copy)
@@ -36,11 +36,12 @@
 
 	closest: function( selector ) {
 		var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
-			closer = 0;
+			closer = 0,
+			stop = this.context.parentNode;
 
 		return this.map(function(){
 			var cur = this;
-			while ( cur && cur.ownerDocument ) {
+			while ( cur && cur.ownerDocument && cur !== stop ) {
 				if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
 					jQuery.data(cur, "closest", closer);
 					return cur;

Download in other formats:

Original Format