Change background color of a div using the id - Javascript:
//function to change background color of a div
function changeBackgroundColor(id) {
//get the div with the id
const div = document.getElementById(id);
//change the background color of the div to red
div.style.backgroundColor = "red";
}
//example
changeBackgroundColor("div1");
Top comments (0)