Skip to content

#11124: context parameter for .is #651

Closed
wants to merge 2 commits into from

4 participants

@gibson042
jQuery Foundation member
  249868   (+239) jquery.js
   94095    (+45) jquery.min.js
   33404    (+19) jquery.min.js.gz
@addyosmani
jQuery Foundation member

Thanks for the PR!

#10868 (http://bugs.jquery.com/ticket/10868) which the ticket for this issue references as solving was voted down due to concerns about feature creep (i.e we couldn't justify the usecase for 10868 enough for the code additions). Beyond filling in the gap between Element.matches and jQuery.fn.is, are there many cases where people are going to need the solution in #11124? I guess I'm having a hard time seeing a need for this in core.

Others may disagree :)

@rwaldron
jQuery Foundation member
rwaldron commented Jan 2, 2012

I feel bad that you put in all this effort when we've unanimously voted "-1" on the original ticket http://bugs.jquery.com/ticket/10868

@gibson042
jQuery Foundation member

I interpreted dmethvin's comment as a challenge to impress rather than an outright downvote, which I still intend to deliver on. And this PR can go in and be useful without full-fledged preimage functionality. But even if both ultimately flop, I've still discovered bug 11109 and gotten more familiar with the selection/filter logic, which will be valuable for future work.

Don't feel bad... at worst, it's just part of my jQuery core learning process.

@gibson042
jQuery Foundation member

As for utility, the context parameter makes it possible to check everything about elements (including siblings/ancestry) with one method call. The most obvious application to me is delegating event listeners for nesting structures:

$( list ).on( "click", "li", function() {
  if ( $( this ).is( "> .clickable", list ) ) {
    return listener.apply( this, arguments );
  }
});

(since $( list ).on( "click", "> li.clickable", listener ) doesn't work).

@dmethvin
jQuery Foundation member

Since we closed the ticket wontfix, we won't land this.

@dmethvin dmethvin closed this Jan 31, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.