1. Use an ID if Possible
HTML ID attributes are unique in every page and even older browsers can locate a single element very quickly:
|
|
2. Avoid Selecting by Class Only
The following class selector will run quickly in modern browsers:
Unfortunately, in older browser such as IE6/7 and Firefox 2, jQuery must examine every element on the page to determine whether “myclass” has been applied.
The selector will be more efficient if we qualify it with a tag name, e.g.
|
|
jQuery can now restrict the search to DIV elements only.
more >>