Is there a difference between $(e.currentTarget) and $(this)?

后端 未结 1 790
再見小時候
再見小時候 2021-02-18 22:52

is there any difference between the following two methods? is #1 faster than #2 ?

#1
$(\'#selector\').on(\'click\',function(){
  $(this)...
  // do stuff with cl         


        
1条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-18 23:40

    Seems like they are equivalent in most cases, though "this" seems easier to type

    according to http://api.jquery.com/event.currentTarget/

    event.currentTarget

    This property will typically be equal to the this of the function.

    If you are using jQuery.proxy or another form of scope manipulation, this will be equal to whatever context you have provided, not event.currentTarget

    0 讨论(0)
提交回复
热议问题