1. Updated version
2. Use the appropriate selector
$ (' #id ') best-of-breed positioning DOM element that can be searched at the target element's closest ID element
$ (' div ') second choice
$ ('. class ') more complex should be used selectively
$ (' [attribute=value] ') poor performance impact, avoid use
$ (': Hidden ') poor performance impact try not to use can be found at the parent or filter $ (' #content '). Find (': Hidden ')
$ (' A.button '). Filter (': Hidden ')
3. Cache objects
var $xxx =$ (' #xxx aaa.bbb ')
4, the loop to the DOM operation, should pay attention to as little as possible DOM operation.
5. When using jquery objects in arrays, it is recommended to use the for and while loops instead of $.each (), which can be faster code runs.
6, the event agent the following three kinds of code to the second and third first
First type $ (' #myTable TD '). Click (function () {$ (this). CSS (' background ', ' red ');}) The second type of $ (' #myTable '). Click (function (e) {var $cilcked =$ (e.target); $cilcked. css (' background ', ' red ');}) The third type of $ (' #myTable '). On (' Click ', ' TD ', function () {$ (this). CSS (' background ', ' red ');})
7. Translate the duplicate code into a plugin
8. Use join () to stitch the string
9, try to use the native JS method
jquery Performance Optimization