Skip to content Skip to sidebar Skip to footer

How Can I Create Interchangeable Instructions?

document.body.style.backgroundColor='#F00'; This statement styles the body background color as red. In my original code I have a function that assigns elements by tag name to a gl

Solution 1:

I'm not too certain of what you mean by "substituting" backgroundColor, but I'll wager a guess that you're trying to access the backgroundColor property programmatically. If so, your second function needs the following amendment:

functionattemptStyle(property,value){
  document.body.style[property]=value;
}

Thus, if you call attemptStyle('backgroundColor', 'red'), you will make the background color of the document red.

Solution 2:

This may not answer your question, but can fix your problem. You are trying to change colors when the mouse is over an element. This can be done simply with CSS

<style>button {
    background-color:#fff;
}

button:hover {
    background-color: #131519
}
</style><button>
function assignStyle(value){}
</button><br /><button>
function attemptStyle(param,value){}
</button>

Post a Comment for "How Can I Create Interchangeable Instructions?"