Bug Tracker

Ticket #2773 (closed enhancement: fixed)

Opened 7 years ago

Last modified 4 years ago

$.fn.is and $.fn.not should accept DOMelements and jQuery collections

Reported by: paul Owned by: timmywil
Priority: low Milestone: 1.6
Component: traversing Version: 1.4.4
Keywords: Cc:
Blocking: Blocked by:

Description

This is basically an addition to #2579. I have had this usecase in almost any UI plugin: The simple task, that I want to see if my DOMelement is within the current jQuery set.

Right now, I have to do something like this:

var inset = false; $(..).each(function() {

if(this == myElement) inset = true;

});

This would be /much/ easier and logical if I could simply do

$(..).is(myElement)

Attachments

is.diff Download (453 bytes) - added by flesler 6 years ago.

Change History

Changed 6 years ago by flesler

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to open

Patch still seems to be okay for 1.4.4 and it's been requested a few times.

comment:2 Changed 4 years ago by ajpiano

$.fn.not already does accept a DOM element (as does $.fn.filter). +1 on $.fn.is. What *really* needs to take a DOM element that doesn't now is $.fn.find and $.fn.closest, IMO. Thoughts?

comment:3 Changed 4 years ago by timmywil

Made a fiddle for this ticket.  http://jsfiddle.net/timmywil/xWNJe/ $.fn.not works properly, $.fn.is does not. .find() and .closest() fail, but .children() and .parent() pass.

comment:4 Changed 4 years ago by timmywil

Something like this might be a start. I'm sure it could be optimized and included in is rather than a new function, but just to use fiddle, here is a newIs that can check objects and raw elements, then passes off to .is() for strings.  http://jsfiddle.net/timmywil/xWNJe/9/. However, I am using indexOf for an array and I don't think ie6 or ie7 support javascript 1.6. There may be something more clever to use, or a fallback should be written for those browsers.

comment:5 Changed 4 years ago by timmywil

Scratch all that. See pull request.

comment:6 Changed 4 years ago by rwaldron

Can you post a link to the pull request?

comment:7 Changed 4 years ago by jitter

  • Status changed from open to assigned
  • Component changed from core to traversing
  • Priority changed from major to low
  • Version changed from 1.2.3 to 1.4.4
  • Milestone changed from 1.2.4 to 1.next
  • Owner set to timmywil

3rd party  pull request

comment:8 Changed 4 years ago by timmywil

 Updated pull request Switched to follow jQuery bug patching guidelines.

comment:9 Changed 4 years ago by ajpiano

  • Milestone changed from 1.next to 1.6

comment:10 Changed 4 years ago by john

  • Status changed from assigned to closed
  • Resolution set to fixed

Landed.

Note: See TracTickets for help on using tickets.