Bug Tracker

Modify

Ticket #7991 (closed enhancement: wontfix)

Opened 2 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 2 years ago by rwaldron

  • Owner set to rwaldron
  • Priority changed from undecided to low
  • Status changed from new to assigned
  • Component changed from unfiled to traversing

comment:2 Changed 2 years ago by ajpiano

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

comment:3 Changed 2 years ago by rwaldron

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

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

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

comment:4 Changed 2 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.