Bug Tracker


Ticket #11508 (closed enhancement: invalid)

Opened 2 years ago

Last modified 2 years ago

$.fn.is() could be enhanced to check existence.

Reported by: andy@… Owned by:
Priority: low Milestone: None
Component: core Version: 1.7.2
Keywords: Cc:
Blocking: Blocked by:


$.fn.is() could be modified slightly to check the existence of the selector parameter. If no parameters are present, it could return this.length > 0 as a nice short-hand.


var form = $('form');
$.post(form.attr('action'), form.serialize());

A common jQuery newb error is to check a jQuery object for truthiness; of course this fails because an empty jQuery object still exists. $.fn.is() though could could be a quick, easy, and valuable shortcut.

See a duck-punched version in action here:  http://jsfiddle.net/bReG4/

Change History

comment:1 Changed 2 years ago by sindresorhus

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to core

You can already do this with the .length property.

"if( !form.find(':input.dirty').length )"

comment:2 Changed 2 years ago by Andy Edinborough <andy@…>

Yes, I know you can. :] I was only offering this as an explicit method that didn't rely on the implicit nature of truthiness.

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


Add a comment

Modify Ticket

as closed

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

Note: See TracTickets for help on using tickets.