I'm practicing using constructor function/objects. I want to style some divs with CSS dynamically using this type of object. I'm trying to get the divs with document.getElementById but am not able to style them. I'm getting the error message 'cannot set backgroundColor of undefined'. It seems i'm not actually getting the element I want or it's not being saved to the variable.
How can I get the element and pass it through the construtor function?
<div id='div1'>div1</div>
<div id='div2'>div2</div>
function StyleDiv(id) {
document.getElementById('id');
this.style.backgroundColor = 'blue';
this.style.height = '110px';
this.style.width = '110px';
}
var div1st = new StyleDiv('div1');
var div2nd = new StyleDiv('div2');