PedroPombo
PedroPombo

Reputation: 23

Javascript styling element

I'm trying to make a function that will set css params to element. I have the following code:

var css = function(k, l){
    for(key in l){
        k.style.key = l[key];
    }
}

But it is not working. I think it's because of the key variable. Is there some way to make it work?

Upvotes: 1

Views: 40

Answers (1)

taxicala
taxicala

Reputation: 21789

First, declare key as var in order to make it strict, and then, you have to access the property of style with brackets:

var css = function (k, l) {
    for (var key in l) {
        k.style[key] = l[key];
    }
}

Upvotes: 2

Related Questions