| From | Sent On | Attachments |
|---|
| 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 | |
Refine Search
| From | Sent On | Attachments |
|---|---|---|
| Josh Nathanson | Oct 30, 2007 9:55 am | |
| Eric Martin | Oct 30, 2007 10:44 am | |
| Wizzud | Oct 30, 2007 11:20 am | |
| Josh Nathanson | Oct 30, 2007 12:57 pm | |
| Yehuda Katz | Oct 30, 2007 1:43 pm | |
| Klaus Hartl | Oct 31, 2007 3:06 am | |
| Josh Nathanson | Oct 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;
--Klaus

