I have a website with a couple of elements like this:
<g class="box" rel="1">...</g>
<g class="box" rel="2">...</g>
<g class="box" rel="3">...</g>
<g class="box" rel="4">...</g>
<g class="box" rel="5">...</g>
In my code I want to change some attributes of these elements in a loop. What I have done at first was this (it works fine for me):
for(var i = 0, l = relValList.length; i < l; i+=1){
$(".box[rel=" + relValList[i] + "]").children().first().attr("fill","#000000");
}
Now I have read a jQuery best practices article, where i found something called caching to increase the performance.
So I try it.
//call this when page loaded
var boxes = $(".box");
//the good old loop
for(var i = 0, l = relValList.length; i < l; i+=1){
//here is my problem
boxes ????
}
What is the best way to get a specific element from boxes by its rel attribute?
Thanks!