[jQuery] UPDATED - possibility complicated color codingquestion, now with example...

[jQuery] UPDATED - possibility complicated color codingquestion, now with example...

Okay...
I've got a working version online:
http://commadelimited.com/travian/maptest.cfm
I've got a few more questions.
1) The page will always load with at least one class preset (based on the
user's choice). What I want to happen is for the user to be able to toggle
back and forth between 2 possible views. I thought I could simply duplicate
the code and swap some values and have it work. However, once I've clicked
both buttons, I can no longer get the values to change colors. What's
actually going on behind the scences when I "addClass"? If I search for .p25
and add .pLev25 to it, does .p25 exist on that item any longer?
2) It's a little slow. I changed up the display to present 300 divs which is
an average of how many items might be on the page at once. How can I change
my code to increase the speed?
3) When you click either button, the js code works great. However, click the
other button and the colors are wrong for the values they contain. What am I
doing wrong?
4) I used your code, but added in a for loop like so:
function colorPop() {
    var values = [25,50,75,100];
    for (i=0;i < values.length;i++) {
        $('.p'+values[i]).each(function(){
            var t = $(this);
            if (t.is('.p'+values[i])) {
                t.addClass('pLev'+values[i]);
            }
        })
    }
}
<!----------------//------
andy matthews
web developer
certified advanced coldfusion programmer
ICGLink, Inc.
andy@icglink.com
615.370.1530 x737
--------------//--------->
-----Original Message-----
From: discuss-bounces@jquery.com [mailto:discuss-bounces@jquery.com]On
Behalf Of Jonathan Sharp
Sent: Monday, August 07, 2006 3:52 PM
To: jQuery Discussion.
Subject: Re: [jQuery] UPDATED - possibility complicated color
codingquestion, now with example...
Your example didn't work for me. A few minor changes though:
function colorPop() {    $('.p25').addClass('pLev25');}function colorTotal()
{    $('.p25').addClass('pLev25');}
Your class is p25 not pop25...
You can grab all of the classes like:
$('.p25, .p50, .p75, .p100').each(function(){
var t = $(this);
if (t.is('.p25')) {
t.addClass('pLev25');
} else if (t.is('.p50')) {
t.addClass('pLev50');
}
});
Hope this helps... (it's best to store a reference t since you'll be calling
the jquery object multiple times)
-js


























































    • Topic Participants

    • andy