Hi,

I have some selectors - an example would be $("#LinkToPreviousHit")
all of which work fine when used directly.

If I use it to toggle the class, which also works, I might do -
$("#LinkToPreviousHit").attr({"class": "activeNavButton"});

since I am using my selectors in multiple places I figured I would
remove the multiple class to the selector and move it into an object -
here is what I have (names will probably be changed when working)

var NavDisplay = {
NextHitB: $("#LinkToNextHit"),
LastHitB: $("#LinkToPreviousHit"),
ToggleNext: function(switcher){
if(typeOf(switcher)==='undefined' || typeOf(switcher) === null){
switcher = Boolean(!navTrack.NextHitInactive);
}
if(switcher){

                        navTrack.NextHitInactive = true;
                        NavDisplay.NextHitB.attr({"class": 
"inactiveNavButton"});

                        }else{
                        navTrack.NextHitInactive = false;
                        NavDisplay.NextHitB.attr({"class": "activeNavButton"});
                        }
},
ShowPrevious: function(switcher){
if(typeOf(switcher)==='undefined' || typeOf(switcher) === null){

switcher = Boolean(!navTrack.HasPrevious);
}
if(switcher){

                        if(!navTrack.HasPrevious){

                NavDisplay.LastHitB.attr({"class": "activeNavButton"});

                navTrack.HasPrevious=true;
                        }

                        }else{


                        if(navTrack.HasPrevious){

                        NavDisplay.LastHitB.attr({"class": 
"inactiveNavButton"});
                        navTrack.HasPrevious=false;
                        }
                        }
}



};

I have also tried using it as window.NavDisplay with no result. There
are no errors raised and the properties of the navTrack object are
changed correctly. However the class is never switched between
inactiveNavButton and activeNavButton or vice versa. As soon as I use
the selectors directly - for example as in the following:

var NavDisplay = {
NextHitB: $("#LinkToNextHit"),
LastHitB: $("#LinkToPreviousHit"),
NextHitInactive: function(){
                        navTrack.NextHitInactive = true;
                        NavDisplay.NextHitB.attr({"class": 
"inactiveNavButton"});
                        },
ToggleNext: function(switcher){
if(typeOf(switcher)==='undefined' || typeOf(switcher) === null){
switcher = Boolean(!navTrack.NextHitInactive);
}
if(switcher){

                        navTrack.NextHitInactive = true;
                        $("#LinkToNextHit").attr({"class": 
"inactiveNavButton"});

                        }else{
                        navTrack.NextHitInactive = false;
                        $("#LinkToNextHit").attr({"class": "activeNavButton"});
                        }
},
ShowPrevious: function(switcher){
if(typeOf(switcher)==='undefined' || typeOf(switcher) === null){

switcher = Boolean(!navTrack.HasPrevious);
}
if(switcher){

                        if(!navTrack.HasPrevious){

                        $("#LinkToPreviousHit").attr({"class": 
"activeNavButton"});

                navTrack.HasPrevious=true;
                        }

                        }else{


                        if(navTrack.HasPrevious){

                        $("#LinkToPreviousHit").attr({"class": 
"inactiveNavButton"});
                        navTrack.HasPrevious=false;
                        }
                        }
}



};

then it works fine.

Is there any reason why my current caching of the selector is not
working? And is there any way you can suggest whereby I can cache my
selector that will work?


Reply via email to