Hmm. Would this be expected to work? $gallery.find('li[title='+$title_to_searchl+']').css('color','red');
On Aug 28, 1:31 pm, tatlar <robertlnew...@gmail.com> wrote: > Oops. This sentence: > "I want to traverse the array, looking at the title attribute, and if > it is in the array $search I want the style changed. " > Should be: > "I want to traverse the list, looking at the title attribute, and if > it is in the array $search I want the style changed." > > And this: > > var $title_to_search = value; > // pseudo code.... I know this is junk > $gallery.find('li').attr('title',$title).css('background- > color','red'); > > Should be: > var $title_to_search = value; > // pseudo code.... I know this is junk > $gallery.find('li').attr('title',$title_to_search).css('background- > color','red'); > > On Aug 28, 1:27 pm, tatlar <robertlnew...@gmail.com> wrote: > > > > > i think this is a pretty simple question, but i can't seem to figure > > it out. > > > i have a list in a div: > > > <div id="gallery"> > > <ul> > > <li title="foo">foo</li> > > <li title="bar">bar</li> > > <li title="unicorn">unicorn</li> > > </ul> > > </div> > > > I have an array with values in it: > > > var $search = [ "foo", "bar" ] ; > > > I want to traverse the array, looking at the title attribute, and if > > it is in the array $search I want the style changed. > > Note that #gallery has about 450 list items - the one above is > > abridged for this post. > > The array $search will at most have 5 items. > > > So, is it faster to do a $.each() on the list items, or do a $.each() > > on the $search items. I am pretty sure it is faster to do the latter, > > but I am not sure how to get the title attribute from the list items > > for the match. > > > Something like? > > > $.each( $search, function(i, value) { > > var $title_to_search = value; > > // pseudo code.... I know this is junk > > $gallery.find('li').attr('title',$title).css('background- > > color','red'); > > > }); > > > Can someone refine this for me? Thanks in advance.