Performance of jQuery selector with context

后端 未结 6 1443
南方客
南方客 2020-12-01 05:26

I was reading this article by Brandon Aaron here, about how jquery context may help. So i thought of doing a test of my own. So this is what I did.

  1. Created

6条回答
  •  醉话见心
    2020-12-01 06:19

    It would make sense that it would take longer to use a context (vs. using a selector alone) since internally, the context uses the .find() method, so in essence, all you are really doing is

    $('#context').find('#holder');
    

    I mainly see it as an easier way to identify elements in events and iterators where the context changes because

    $('.holder', this)
    

    is prettier than

    $(this).find('.holder')
    

提交回复
热议问题