0

I am unable to change dom element style with JavaScript function. Element id and style value can be passed to function as parameters but style parameter(example "color") will not passed. Is there any good way to resolve it? "first" - element id "color" - style parameter "green" - style value

styleToDom("first", "color", "green")
        
function styleToDom(id, parameter, value){
     document.getElementById(id).style.parameter = value
}
mmeest
  • 11
  • 3

1 Answers1

0

I guess you could use this.

function styleToDom(id, parameter, value) {
    document.getElementById(id).style.cssText += `${parameter}: ${value}`;
}
tarcseh
  • 21
  • 2
  • 4