+ 1
Changing background color through JavaScript
How would I do this? I’m looking to make a option drop-down that will change the background color depending on the option chosen.
2 Respostas
+ 6
Basically add a change event listener to the top level element(in this case select tag) then if it matches the clicked element change the background color to that one.
select.addEventListener('change',
function(e){
if(e.target && e.target.nodeName =="SELECT"){
body.style.backgroundColor = e.target.value
}
})
//demo code
https://code.sololearn.com/W7Fta4ObsASg/?ref=app
+ 3
You can write:
document.style.backgroundColor= '#ABCDEF';
You can see this code it has something related to your query
https://code.sololearn.com/WCHCllYIH6KR/?ref=app