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

<<First <Back | 1537 | 1538 | 1539 | 1540 | 1541 | 1542 | 1543 | 1544 | 1545 | 1546 | Next> Last>>







Share CertificationPoint & Stay Informed Socially About EduTech?