1

I need select the tr of thead

$("#table > thead > tr");

Is much the difference respect to this:

$("#table").find("thead").find("tr");

Is there a way to optimize this jquery selector, what is the best?

FQuijada
  • 219
  • 1
  • 11
  • 1
    You can test this yourself at jsperf.com: https://jsperf.com/jquery-methods-vs-selectors/1. In Chrome on windows at least, using method calls is roughly 3 times faster in this scenario. That won't always be the case though. It depends on your HTML structure and the complexity of the selector. In the real world you won't notice a difference. I'd argue if you're this concerned over JS performance, then you shouldn't be using jQuery at all. – Rory McCrossan Mar 29 '18 at 16:11
  • Your answer is very interesting, in your experience, what technology do you recommend to replace jquery? – FQuijada Mar 29 '18 at 17:30
  • 1
    If you want pure speed, then nothing. Use plain JS. Any framework will be slower as it's an abstraction – Rory McCrossan Mar 29 '18 at 17:38

0 Answers0