Skip to content Skip to sidebar Skip to footer

How To Change Div Background Color On Button Click?

I can change the background color Red, Blue, as well as Green, but when I click the Reset button I get an error in Chrome(browser): btnReset is not a function, How to make all div

Solution 1:

Be careful when you're using id on the html tags, because it makes an automatic var declaration using the id. So, you're overriding the btnReset function with the btnReset pointing to the <input>.

Solution 1: change the id="btnReset" or the function btnReset() name!

Solution 2: move your <script> to the end of the document (just before the </body> end tag, so your function overrides the automatic declarated var.

Additional info: http://www.2ality.com/2012/08/ids-are-global.html

Post a Comment for "How To Change Div Background Color On Button Click?"