extendify!

$(document).ready(function() {
        jQuery.fn.exists = function() {
                return ( this.is('*') )
                }
        }
});

On Dec 27, 10:28 am, "Michael Geary" <[EMAIL PROTECTED]> wrote:
> It's funny, if I saw:
>
> if( $('#id').is('*') ) { ... }
>
> I would have no clue what the code was trying to do until I thought hard
> about it: "Let's see... is star... Now that's going to match *anything*.
> Wouldn't it always return true? Naw, that can't be right, what would be the
> point of this code... Oh! What if there are no elements at all? Then it
> would return false! I think it would anyway. Better check the docs. Hmm...
> The docs don't explicitly say what .is() does when the array is empty.
> Better check the source code, and maybe try a couple of test cases to be
> sure."
>
> Where if I saw:
>
> if( $('#id').length ) { ... }
>
> I would know right away what it does: "$() returns an array. Does it have
> any elements?" :-)
>
> -Mike
>
>
>
> > From: McLars
>
> > $('#id').length is the old school, and most widely used, technique.
> > This is probably the fastest.
>
> > $('#id').is('*') does make sense semantically (expresses the
> > intent), and is more flexible.
> > > From: Alexey Blinov
>
> > > Yep... my code have size(). Forgot to point it...
> > > And thanks for info about more efficient way - using length.
> > > So... which way is better than?
>
> > > 1. $('#id').length > 0
>
> > > 2. $('#id').length() !== 0
>
> > > 3. $('#id').is('*') //never try it... but look pretty- Hide quoted text -
>
> - Show quoted text -

Reply via email to