Detect DOM object vs. jQuery Object

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

    elm instanceof jQuery is the most foolproof way, as testing elm.nodeType would mistake {nodeType:1} for a DOM element, and testing elm.jquery would mistake {jquery:$()} for a jQuery object, in addition to there being no guarantee future jQuery objects won't have a jquery property.

提交回复
热议问题