Reputation: 11
Is there anyway I can set up a style property dynamically to an objects property? I tried the code below and got an error.
var page = {showElement:'none'};
var markup='<div id="button"> </div><style>#button{display:'+page.showElement+';}</style>';
var mainDiv = document.getElementById('mainDiv');
mainDiv.innerHTML = markup;
Upvotes: 0
Views: 68
Reputation: 16675
You already have an ID for your div element, why not use it to change the display property?
document.getElementById('button').style.diplay = 'none';
or
document.getElementById('button').style.diplay = page.showElement;
So you dont really need to use:
mainDiv.innerHTML
Upvotes: 1