javascript - Avoiding duplicated dom queries? -


i learning avoid duplicated dom queries. recommendation far save initial query variable , re-use variable needed.

question:

if save following variable:

var mylist = $("ul.mylist"); 

will following make dom query?

mylist.find("li:first"); 

or search within variable?

if so, there better way it? avoid query?

yes, "dom query". have 1 look-up can save list item node jquery wrapper in variable

var mylist = $("ul.mylist li:first"); 

or, can manually search within dom properties of unordered list, jquery, believe, won't you, using .find() method.

var mylist = $("ul.mylist"); mylist[0].children[0]; // or using jquery mylist.first(); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -