Skip to main content

Bug Tracker

Side navigation

#11508 closed enhancement (invalid)

Opened March 23, 2012 12:07AM UTC

Closed March 23, 2012 12:29AM UTC

Last modified March 23, 2012 12:33AM UTC

$ could be enhanced to check existence.

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

$ 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. $ though could could be a quick, easy, and valuable shortcut.

See a duck-punched version in action here:

Attachments (0)
Change History (2)

Changed March 23, 2012 12:29AM UTC by sindresorhus comment:1

component: unfiledcore
priority: undecidedlow
resolution: → invalid
status: newclosed

You can already do this with the .length property.

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

Changed March 23, 2012 12:33AM UTC by Andy Edinborough <> comment:2

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