开发者

How can I tell if a variable is wrapped in jQuery or not?

开发者 https://www.devze.com 2023-04-10 20:41 出处:网络
I have a function that has the signature of: function(id,target){ //do stuff } The target parameter is assumed to be a jQuery wrapped object however it is possible that it could be a dom element i

I have a function that has the signature of:

function(id,target){
 //do stuff
}

The target parameter is assumed to be a jQuery wrapped object however it is possible that it could be a dom element in which 开发者_开发知识库case I'd like to wrap it in jQuery before I do operations on it. How can I test the target variable for jQuery?


if(!(target instanceof jQuery)) {
  target = jQuery(target);
} 


You can use instanceof

obj instanceof jQuery

Check if object is a jQuery object

0

精彩评论

暂无评论...
验证码 换一张
取 消