Reputation: 232
this is probably ver simple but I cannot figure it out.
how can I assign the objects values to the buttons style atribute in the for loop below?
(function(){
var parent = {
color: "orange",
width: "50px",
height: "50px"
},
child = Object.create(parent),
button = document.querySelector("button");
button.onclick = function(){
for (var test in child) {
button.style.test = // ??
}
}
})();
thanks in advance
Upvotes: 0
Views: 306
Reputation: 145398
For such cases there is a square bracket notation:
button.style[test] = child[test];
MORE: http://www.javascripttoolbox.com/bestpractices/#squarebracket
Upvotes: 4