I'm trying to optimize some code that currently works by having one function add a class to elements that meet certain criteria and another function that applies effects to them based on the classes attached. I found that adding and removing classes was relatively slow so instead I want to build up an array of elements and use that for filtering.
I can't provide actual code because a) I'm working under an ND and b) I'm at home now and it's all at work anyway, but basically in the function that applies the effects I'd have something that was functionally similar to this: elements = $('.globalClass'); elementsToHide = elements.filter ('.unselected').not (':hidden'); elemsToAnimate = elements.not ('.unselected'); elementsToShow = elementsToAnimate.filter (':hidden'); // Do stuff elements.removeClass ('.unselected'); The functions that would decide what elements should be selected would addClass ('unselected'). I am optimizing this code to run faster, and as DOM access can be rather slow I decided that I would build an array of elements instead. My first attempt involved building an array of strings, each string being an element ID, and then using Array.join() to build a query string for use in filtering. The logic portion was faster because it was now just pushing vars onto an array, but the effects functions took considerably longer to start because either the string manipulation or using filter() and not() with long strings of element IDs was slow. My second attempt to speed things up involved pushing getElementById returns onto my array instead. I was hoping to use code along these lines to access the array: elements = $('.globalClass'); elementsToHide = elements.filter (unselectedArr).not (':hidden'); elemsToAnimate = elements.not (unselectedArr); elementsToShow = elementsToAnimate.filter (':hidden'); But because you don't seem to be able to pass arrays of elements to filter it didn't work. On Jun 20, 6:10 pm, "John Resig" <[EMAIL PROTECTED]> wrote: > Can you provide an example of the code? I'm not sure what you're > trying to do from your description. (If I had to guess, I'd say that > you're trying to pass an element to filter, but I'm not sure why.) > > --John > > On 6/20/07, Gordon <[EMAIL PROTECTED]> wrote: > > > > > If I build up a list of elements by pushing elements retrieved > > getElementById onto an array and pass it to not() I can use this list > > to filter out elements I don't want. But when I try the same thing > > with filter() I get an error message: > > > t.substring is not a function > >http://localhost/js/jquery/jquery.js > > Line 2659 > > > I have tried this with both 1.1.2 and 1.1.3a and gotten the same > > result (the error above was from 1.1.3a) > > > >From what I understand filter and not work in a similar way, and that > > not in fact uses filter to do its job. Is there a reason why I can > > pass an array of elements to not but I can't pass one to filter?