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

<<First <Back | 1104 | 1105 | 1106 | 1107 | 1108 | 1109 | 1110 | 1111 | 1112 | 1113 | Next> Last>>







Share CertificationPoint & Stay Informed Socially About EduTech?