atom feed7 messages in com.googlegroups.jquery-enRe: [jQuery] Re: Test if object is jQ...
FromSent OnAttachments
Josh NathansonOct 30, 2007 9:55 am 
Eric MartinOct 30, 2007 10:44 am 
WizzudOct 30, 2007 11:20 am 
Josh NathansonOct 30, 2007 12:57 pm 
Yehuda KatzOct 30, 2007 1:43 pm 
Klaus HartlOct 31, 2007 3:06 am 
Josh NathansonOct 31, 2007 9:55 am 
Subject:Re: [jQuery] Re: Test if object is jQuery object
From:Josh Nathanson (josh@gmail.com)
Date:Oct 31, 2007 9:55:38 am
List:com.googlegroups.jquery-en

var isJQuery = obj instanceof jQuery;

Thanks Klaus and Yehuda, I think I like this better than just checking if there is a property 'jquery' on the object. That would work too, but 'instanceof' is exactly what I'm checking for.

-- Josh

----- Original Message ----- From: "Klaus Hartl" <klau@googlemail.com> To: "jQuery (English)" <jque@googlegroups.com> Sent: Wednesday, October 31, 2007 3:06 AM Subject: [jQuery] Re: Test if object is jQuery object

On 30 Okt., 17:55, "Josh Nathanson" <josh@gmail.com> wrote:

Is there a cool way to check if an object is a jQuery object as opposed to any other object?

I tried the constructor property but it just says Object(), the same as any other object.

Tried typeof, but same deal, just object.

Right now my function can take an object or a jQuery object as an argument, and all I've figured out is that the jQuery object is indexable (array-like), so if the object is not jQuery it will return undefined if I say obj[0]. But, this seems like a hack - is there a better way to test the object's type?

-- Josh

Try:

var isJQuery = obj instanceof jQuery;