Compare 'e.target' to a jQuery object

后端 未结 4 1482
情书的邮戳
情书的邮戳 2021-02-06 22:00

What I want to do:

( clickedObject === someDiv ) //returns true or false

What I tried

( $(e.target) === $(\'.selector\') ); //r         


        
4条回答
  •  忘掉有多难
    2021-02-06 22:43

    To check if e.target has this class you can use the hasClass function.

    if ($(e.target).hasClass("selector"))
    

    Or, if you really want to compare objects, note that jQuery selectors return a collection of items, so I think you'll want

    if (e.target === $('.selector')[0])
    

提交回复
热议问题