Detect DOM object vs. jQuery Object

后端 未结 6 1457
忘掉有多难
忘掉有多难 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:28

    To test for a DOM element, you can check its nodeType property:

    if( elm.nodeType ) {
        // Was a DOM node
    }
    

    or you could check the jQuery property:

    if( elm.jquery ) {
        // Was a jQuery object
    }
    

提交回复
热议问题