Detect DOM object vs. jQuery Object

后端 未结 6 1465
忘掉有多难
忘掉有多难 2021-01-31 08:55

I have a function that I want to be able to allow passing in either a regular javascript DOM element object or a jQuery object. If its not yet a jQuery object I will then make i

6条回答
  •  心在旅途
    2021-01-31 09:49

    To test for a jQuery object, you can use the instanceof operator:

    if(elm instanceof jQuery) {
        ...
    }
    

    or:

    if(elm instanceof $) {
        ...
    }
    

提交回复
热议问题