如何知道对象是否是jQuery对象

时间:2011-12-15 13:04:01

标签: jquery

我已经创建了一个函数,它告诉变量持有jQuery对象或者是否有替代它。以下是我的代码

/*Is there any substitute of this function*/

function iSJqueryObj(elm)
{
    return elm && jQuery.isFunction(elm.html);
} 

http://jsfiddle.net/kE7Lp/3/

2 个答案:

答案 0 :(得分:12)

使用instanceof

console.log(elm instanceof jQuery);

或:

console.log(elm instanceof $);

演示:http://jsfiddle.net/karim79/8jUKX/

答案 1 :(得分:3)

尝试

实例
obj instanceof jQuery