$("#content").find(".abc") The .find() method will call the browser's native methods (getElementById, getElementByName, getElementByTagName, etc.), so it is faster. Much faster than $("#content .abc") About jQuery selector efficiency, you can refer to the performance analysis http://blog.csdn.net/cxl44490...
The test result is that find is faster The reason is that the selection order of various selector chains used internally by jQuery is from right to left, so this statement first selects .abc, and then filters out the parent element #content one by one, which results in It's much slower. At the same time, the .find() method will call the browser's native methods (getElementById, getElementByName, getElementByTagName, etc.), so it is faster. Comparing the two, naturally find is much faster.
The following is the test: https://jsperf.com/jqueryfind...
$("#content").find(".abc") The .find() method will call the browser's native methods (getElementById, getElementByName, getElementByTagName, etc.), so it is faster. Much faster than $("#content .abc")
About jQuery selector efficiency, you can refer to the performance analysis http://blog.csdn.net/cxl44490...
The test result is that find is faster
The reason is that the selection order of various selector chains used internally by jQuery is from right to left, so this statement first selects .abc, and then filters out the parent element #content one by one, which results in It's much slower.
At the same time, the .find() method will call the browser's native methods (getElementById, getElementByName, getElementByTagName, etc.), so it is faster.
Comparing the two, naturally find is much faster.
The following is the test: https://jsperf.com/jqueryfind...
The second one is faster