Can I use JQuery functions on a variable and not have JQuery reference the DOM over and over again? -


var x = $("element"); $(x).width(95); 

very, new jquery. want item dom , use jquery functions on item. want make sure not getting item dom on , on again. or getting item dom second time?

if can avoid , use jquery functions? how that?

do need care? feel should.

i want make sure not getting item dom on , on again. or getting item dom second time?

no.

$() returns jquery object contains collection of elements. have been found in dom.

you not need pass $ either, "$":

var x = $("element"); x.width(95); 

if pass $ object $, creates copy of collection - not search items again, clones list.

do need care? feel should.

yes, , should. executing selector against dom can expensive. don't want executing every time.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -