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 ( 170 views )   |  permalink   |  $star_image$star_image$star_image$star_image$star_image ( 3.1 / 454 )

<<First <Back | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | Next> Last>>







Share CertificationPoint & Stay Informed Socially About EduTech?