You can still start off by grabbing your table, and that will make each
individual search for a td quicker.

mytable = $('#mytable');
...
FlexCell = $("[EMAIL PROTECTED]" + ShiftDate + "]", mytable);

Or, even better, you can grab all the td elements that have a dateValue in
the first place.

mycells = $('[EMAIL PROTECTED]');
...
FlexCell = $("[EMAIL PROTECTED]" + ShiftDate + "]", mycells);


As for the rest...  it looks like it would be painful to refactor your
whoe method just to get the selection outside of the iteration.  So,
hopefully, you'll get enough help out of limiting the context that your
speed will go down by a good bit.  Given that it's taking 3 seconds, I'm
guessing that you're running this on a relatively large DOM.  The bigger
the DOM, the more benefit you get from limiting the context.

- Brian


> Brian,
>
> The only problem I see with that is that the dates come from the object
> that I'm looping over.
>
> I maybe should have included the entire for loop in my original post:
>
> for(i = 0; i < ThisRecordCount; i++){
>     ShiftDate = "{ts '" +
> CFJS.ListFirst(FlexOrderData.data.SHIFTDATE[i],".") + "'}";
>     TempDate = $.odbcDateTimeParse(ShiftDate);
>     BackgroundColor = "#ThisWeekdayColor#";
>     if(!(TempDate.getDay() % 6)){
>         BackgroundColor = "#ThisWeekendColor#";
>     }
>
>     FlexCell = $("[EMAIL PROTECTED]" + ShiftDate + "]");
>
> FlexCell.removeClass("CalendarCellDisabled").addClass("CalendarCellEnabled").attr("state",
> "Enabled").css({background:BackgroundColor, color:"#someColdFusionVar#"});
> }
>
> I don't know the ShiftDates ahead of time, nor how many there will be.
> Can I still apply you possible solution?
>
> Thanks,
> Chris
>
> Brian Miller wrote:
>> You can comma-delimit the selector, so you can package up all the td
>> elements you're looking for into one $ function.
>>
>> Also, if you limit your context (to, say, the table in question), it'll
>> help speed things up.
>>
>> mytable = $("#mytable");
>> FlexCells = $("[EMAIL PROTECTED]" + ShiftDate + "], [EMAIL PROTECTED]" +
>> ShiftDate2 + "]", mytable);
>>
>> This is a good start.  Once you have all your elements, you can iterate
>> thorugh them with $.each(), which is relatively speedy.
>>
>> - Brian
>>
>>
>>
>>> Hi gang,
>>>
>>> I've got a for loop in which I have jQuery select a different DOM
>>> element for each iteration. The code I've got that selects the element
>>> is:
>>>
>>>     FlexCell = $("[EMAIL PROTECTED]" + ShiftDate + "]");
>>>
>>> So far, it's taking about three seconds to complete a loop of fifteen
>>> iterations. Yikes! :o( If I remove the above line from the code, it's
>>> lightning quick!
>>>
>>> I should mention that the three second approximation is *after* I
>>> upgraded to the very latest jQuery build (jquery-latest.pack.js... from
>>> the jquery.com main page). So upgrading did give me a slight
>>> performance
>>> increase.
>>>
>>> Can anybody help me speed this up?
>>>
>>> Thanks,
>>> Chris
>>>
>>> --
>>> http://www.cjordan.info



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to