Does Too many ids hurt performance

前端 未结 4 568
名媛妹妹
名媛妹妹 2021-01-17 07:59

If I have in the page unnecessary ids on elements, like the HTML Helper does in ASP.Net-MVC.
Does it reduce the performace of my i

4条回答
  •  野的像风
    2021-01-17 08:49

    Selecting elements by id in jQuery is one of the few selectors that will not receive a performance hit if there are many elements on the page.

    If on the other hand, you were selecting elements based on class or attribute value, you would see a significant performance hit. If you are worried about performance, also make sure to cache your jquery selectors by storing the selectors in variables for reuse.

    var element = $("#specificElement");
    console.log(element.val());
    

提交回复
热议问题