问题描述
我正在寻找任何方法,我可以提高选择器的性能的jQuery调用。具体来说:
I'm looking for any way that I can improve the selector performance of a jQuery call. Specifically things like this:
$(div.myclass)
比 $(。myclass)
我认为它可能是,但我不知道jQuery是否足够聪明,
I would think it might be, but I don't know if jQuery is smart enough to limit the search by tag name first, etc. Anyone have any ideas for how to formulate a jQuery selector string for best performance?
推荐答案
有没有任何想法如何制定一个jQuery选择器字符串以获得最佳性能?
There is no doubt that filtering by tag name first is much faster than filtering by classname.
这是在所有浏览器都实现getElementsByClassName之前的情况。 ,如getElementsByTagName的情况。
This will be the case until all browsers implement getElementsByClassName natively, as is the case with getElementsByTagName.
这篇关于好的方法来提高jQuery选择器的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!