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" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@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" <[EMAIL PROTECTED]> 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;


--Klaus


Reply via email to