How to have efficient selectors (Become an expert)

Throughout the book, I've given several hints to improve performances. This recipe will reinforce some of them and add other useful tips and tricks to improve the performance of your website by simply selecting elements in the right way.

How to do it...

To boost the performances, keep in mind the following points:

  1. Don't use the Universal selector (explicitly or implicitly). Never! Seriously!
  2. The best selectors are the Id, Class and Element selectors, because under the hood jQuery uses native JavaScript functions.
  3. The best performances are achieved using the ID selector.
  4. Never prepend a tag name before an id, it'll slow down the selector. For example, don't turn $('#content') into $('div#content').

Get Instant JQuery Selectors now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.