var - Set jQuery CSS Variable Only Once -


this addresses issue somewhat, not entirely:

optimizing code define variables once, code works when vars in change function , code outside change redefine?

it's pretty elementary requirement -- want class' text color when element dynamically loaded. no problem there:

var follcolor = $('div.followup').css("color"); 

and when condition met, want update class color, references state of application i'm working on:

$('.anyclass').attr('style', 'color:'+follcolor+''); 

the problem variety of conditions can , occur change text's color dynamically after page loaded -- i'll never know which. want initial state can set user , have applicable without ever having follcolor variable reset.

the simplest solution somehow prevent var ever being updated after first time. suggested, there isn't event bind would, example, stop propagation/resetting. i'm stumped , can use here. in advance.

if understand question correctly try this. want if follcolor has value shouldn't change, instead of setting try this:

var follcolor; if(follcolor == null){   follcolor = $('div.followup').css("color"); } 

hope helps.


Comments