vmars316 Posted December 10, 2022 Share Posted December 10, 2022 Hello & TIA , I am trying to change a background color of a <div> backgroundColor with javascript . #fretboardContainer { background-color: #DCDCDC; <button class="button" id="button2" onclick="button2Clicked()">Color</button> <table id="fretboardContainer" style=" position: absolute ; width: 1200px;"> With this code: <script> function button2Clicked() { alert("button2 was clicled") ; document.body.style.backgroundColor = "red"; document.getElementById(fretboardContainer).style.backgroundColor = "#000000" } </script> This is the culprit: document.getElementById(fretboardContainer).style.backgroundColor = "#000000" Pls , what is the proper way to code that ? Link to comment Share on other sites More sharing options...
dsonesuk Posted December 11, 2022 Share Posted December 11, 2022 The error that show's that state's fretboardContainer is undefined as a variable in console, didn't give you a clue?... you didn't look in console log for error, well, maybe you should! Link to comment Share on other sites More sharing options...
vmars316 Posted December 12, 2022 Author Share Posted December 12, 2022 Got it , Thanks... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now