Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7991 closed enhancement (wontfix)

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

Reported by: cobexer Owned by: Rick Waldron
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

Change History (4)

comment:1 Changed 8 years ago by Rick Waldron

Component: unfiledtraversing
Owner: set to Rick Waldron
Priority: undecidedlow
Status: newassigned

comment:2 Changed 8 years ago by ajpiano

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

comment:3 Changed 8 years ago by Rick Waldron

Resolution: wontfix
Status: assignedclosed

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

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

comment:4 Changed 8 years ago by ajpiano

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.

Note: See TracTickets for help on using tickets.