Q&A: Q: How can I set the CSS background color of an HTML element using JavaScript? 
Tuesday, April 21, 2020, 10:58 PM
#edutech #college #work #NFT #education #remotework #onlinelearning #stem #talent #diversity #highered #STEM #blog

Q: How can I set the CSS background color of an HTML element using JavaScript?

A: 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;
}

// where el is the concerned element
var el = document.getElementById('elementId');
setColor(el, 'green');

Comments

Brent - Arizona Univ '91 
Monday, November 15, 2021, 10:32 AM
Thanks for sharing!

Add Comment
Fill out the form below to add your own comments.









Insert Special:
:o) :0l







Moderation is turned on for this blog. Your comment will require the administrators approval before it will be visible.