CSS background color in JavaScript *

Question

How can I set the CSS background color of an HTML element via JavaScript?

Answer

In general, CSS properties are converted to JavaScript by making them camelCase without any dashes. So background-color becomes backgroundColor.

function setColor(element, color)
{
    element.style.backgroundColor = color;
}
< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/3319/" >CSS background color in JavaScript< /a>
Share on Google Plus

About Cinema Guy

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment