Skip to main content

Bug Tracker

Side navigation

#7991 closed enhancement (wontfix)

Opened January 17, 2011 09:31PM UTC

Closed January 18, 2011 12:44AM UTC

Last modified January 18, 2011 12:48AM UTC

jQuery.contains is unintuitive, improve by moving to jQuery.fn

Reported by: cobexer Owned by: rwaldron
Priority: low Milestone: 1.next
Component: traversing Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

The .contains method is only available on the jQuery object but not on Wrapped DOM Nodes, this is inconsistent and unintuitive.

examples:

$(...).hasClass(...)

$(...).is(...)

to me $('#something').contains(...) seems very logical, additional it would be nice if that new method could handle jQuery wrapped DOM Nodes too

Attachments (0)
Change History (4)

Changed January 17, 2011 11:50PM UTC by rwaldron comment:1

component: unfiledtraversing
owner: → rwaldron
priority: undecidedlow
status: newassigned

Changed January 18, 2011 12:41AM UTC by ajpiano comment:2

Isn't this exactly what jQuery.fn.has is for?

Changed January 18, 2011 12:44AM UTC by rwaldron comment:3

resolution: → wontfix
status: assignedclosed

This functionality already exists in the form of find().length, take a look:

if ( poop.find('shoopdawoop').length ) { 
  /* contains shoopdawoop */ 
}

Changed January 18, 2011 12:48AM UTC by ajpiano comment:4

The $.fn.contains that's envisioned here was in pre-release versions of jQuery 1.4 and I was opposed to it then because

a) $.fn.contains shouldn't be different from the pseudoselector :contains, which filters by text

b) it's just a shortcut to .has("foo").length

I don't really think $.contains is unintuive per se, you just have to understand that it's a low level utility for doing a specific job quickly, not a generic traversal method.