Bug Tracker

Opened 15 years ago

Closed 12 years ago

#2773 closed enhancement (fixed)

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

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

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 (1)

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

Download all attachments as: .zip

Change History (11)

Changed 15 years ago by flesler

Attachment: is.diff added

comment:1 Changed 13 years ago by dmethvin

Status: newopen

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

comment:2 Changed 13 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 12 years ago by Timmy Willison

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 12 years ago by Timmy Willison

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 12 years ago by Timmy Willison

Scratch all that. See pull request.

comment:6 Changed 12 years ago by Rick Waldron

Can you post a link to the pull request?

comment:7 Changed 12 years ago by jitter

Component: coretraversing
Milestone: 1.2.41.next
Owner: set to Timmy Willison
Priority: majorlow
Status: openassigned
Version: 1.2.31.4.4

3rd party pull request

comment:8 Changed 12 years ago by Timmy Willison

Updated pull request Switched to follow jQuery bug patching guidelines.

comment:9 Changed 12 years ago by ajpiano

Milestone: 1.next1.6

comment:10 Changed 12 years ago by john

Resolution: fixed
Status: assignedclosed

Landed.

Note: See TracTickets for help on using tickets.