Skip to main content
deleted 15 characters in body
Source Link
user719662
user719662

Yes!

jQuery.fn.exists = function(){ return this.length>0;length > 0; }

if ($(selector).exists()) {
    // Do something
}

There you go!

This is in response to: Herding Code podcast with Jeff Atwood

Yes!

jQuery.fn.exists = function(){return this.length>0;}

if ($(selector).exists()) {
    // Do something
}

There you go!

This is in response to: Herding Code podcast with Jeff Atwood

Yes!

jQuery.fn.exists = function(){ return this.length > 0; }

if ($(selector).exists()) {
    // Do something
}

This is in response to: Herding Code podcast with Jeff Atwood

Improved function: `this` inside a `.fn` function points to a jQuery object. Don't wrap it again.
Source Link
Rob W
  • 350.4k
  • 87
  • 811
  • 683

Yes!

jQuery.fn.exists = function(){return jQuery(this).length>0;}

if ($(selector).exists()) {
    // Do something
}

There you go!

This is in response to: Herding Code podcast with Jeff Atwood

Yes!

jQuery.fn.exists = function(){return jQuery(this).length>0;}

if ($(selector).exists()) {
    // Do something
}

There you go!

This is in response to: Herding Code podcast with Jeff Atwood

Yes!

jQuery.fn.exists = function(){return this.length>0;}

if ($(selector).exists()) {
    // Do something
}

There you go!

This is in response to: Herding Code podcast with Jeff Atwood

added 43 characters in body
Source Link
Jake McGraw
  • 56.2k
  • 10
  • 52
  • 63

Yes!

jQuery.fn.exists = function(){return jQuery(this).length>0;} 

if ($(selector).exists()) {
    // Do something
}

There you go!

This is in response to: Herding Code podcast with Jeff Atwood

Yes!

jQuery.fn.exists = function(){return jQuery(this).length>0;}

There you go!

This is in response to: Herding Code podcast with Jeff Atwood

Yes!

jQuery.fn.exists = function(){return jQuery(this).length>0;} 

if ($(selector).exists()) {
    // Do something
}

There you go!

This is in response to: Herding Code podcast with Jeff Atwood

Source Link
Jake McGraw
  • 56.2k
  • 10
  • 52
  • 63
Loading