Ticket #2773 (closed enhancement: fixed)
$.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
Change History
comment:1 Changed 3 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 3 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 2 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 2 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:7 Changed 2 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 2 years ago by timmywil
Updated pull request Switched to follow jQuery bug patching guidelines.
comment:10 Changed 2 years ago by john
- Status changed from assigned to closed
- Resolution set to fixed
Landed.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

