In the following code, I am trying to set backgroundColor
via a variable prop
. I would like to know the reason as to why div.style.prop
does not work.
var div = document.getElementById('test')
var prop = 'backgroundColor'
div.innerHTML = 'This is some text'
div.style.prop = 'red'