Most efficient way to re-use jQuery-selected elements

后端 未结 4 2411
南方客
南方客 2021-02-20 17:14

I can imagine the correct answer to this based on theory, but I\'m just looking for some confirmation. I\'m wondering what the most efficient way to re-use a jQuery-selected ele

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-20 17:29

    if you're using jQuery selector (like $('#element')), then yes, you should always store your results.

    if you're using object and wrapping it in jQuery (like $(this)), it's not necessary, because jQuery doesn't need to search for that element again.

提交回复
热议问题