javascript - Selectors and performance -


is there benefit performance when following in mootools (or framework, really)?:

var elem = $('#elemid');     elem.addclass('someclass');         elem.set('some attribute', 'some value'); 

etc, etc. basically, i'm updating elements lot on dom , wondering if creating variable in memory , using when needed better than:

$('#elemid').addclass('someclass');     $('#elemid').set('some attribute', 'some value'); 

the changes $('#elemid') on place, in various different functions.

spencer ,

this called caching , 1 of best practices.

when

$('#elemid'); 

it go , query dom everytime , if

var elem = $('#elemid'); 

elem acts cache element , improves performance lot.

this manly useful in ie has memory leaks promblem , all

ready document good

http://net.tutsplus.com/tutorials/javascript-ajax/14-helpful-jquery-tricks-notes-and-best-practices/


Comments