解析jQuery Selectors的效能
Stéphane Caron在解析jQuery Selectors的效能這篇文章中,比較了三種selector的執行效能,有以下的發現:
- $(’.element’) > $(’div.element’) > $(’div.element:first’),表示使用selector的時候,越簡單(層級越少)越好。
- 在position selectors的部份,也有相同的結果(越簡單越好):$(’.sample-elements:first’) > $(’.sample-elements .last:last’), $(’.sample-elements div.last:last’) > $(’.sample-elements div:first’) > $(’.sample-elements div:eq(2)’)。
- ID selectors 如 $(’#second’) 效能遠大於 class selectors,不但執行時間最短,呼叫次數也是最少的。
可能的相關文章:
- [jQuery] Lazy與Lazy Load
- [jQuery] .ajax 在 IE7 中無法執行 success 函式
- [jQuery UI] 讓每個 Tab 擁有獨立網址
- [jQuery] 檢查某個元素是否存在



2. May 2009 at 10:21
[...] 解析jQuery Selectors的效能 [...]