Search  


Q&A: Q: How can I set the CSS background color of an HTML element using JavaScript? 
Tuesday, April 21, 2020, 10:58 PM
Posted by Administrator
#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');
1 comment ( 233 views )   |  permalink   |  $star_image$star_image$star_image$star_image$star_image ( 3.1 / 581 )

<<First <Back | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | Next> Last>>







Share CertificationPoint & Stay Informed Socially About EduTech?