I am trying to change CSS attributes dynamically for given elements in a document, my current solution looks something like this:
function changeEffect(element,choice){ var effects = {}; effects.name1 = {"-webkit-box-shadow" : "7px 13px 21px -1px rgba(0,0,0,0.5)", "-moz-box-shadow" : "7px 13px 21px -1px rgba(0,0,0,0.5)", "box-shadow" : "7px 13px 21px -1px rgba(0,0,0,0.5)" }, effects.name2 = {"-webkit-filter" : "drop-shadow(5px 5px 5px #222)", "filter" : "drop-shadow(5px 5px 5px #222)" }; for(i in effects[choice]){ if(effects[choice].hasOwnProperty(i)){ // using jquery to easily apply changes $(element).css(i,effects[choice][i]); } } }
for example, if I want to apply the effect of name1 to all elements of the img class, then the code:
changeEffect('.img','name1');
my question
Is there a better solution for a similar problem?
source share