How can I tell the difference between a regular object and a jquery object (page element)? [duplicate]

StackOverflow https://stackoverflow.com/questions/21768161

문제

// var = {hey: "baby"};
// or 
// var = $('#thingy');

if(typeof var == 'object'){  // this is true for both =(
}

I need my code to be smart enough to be able to tell the difference between these two. What's the best way to accomplish that?

도움이 되었습니까?

해결책

You can use the instanceof operator for this.

obj instanceof jQuery

In addition, I don't think you want to use "var" as a variable name. It's reserved to establish variable scope.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top