PDA

View Full Version : dynamically change button color



zeero
Jan 5th, 2011, 07:24 PM
Hi all,

I need to make a page that dynamically changes the button background color with an onclick. I'm really new at this so sorry if this is something really simple but was wondering why this doesn't work? Do I need to use javascript or css instead?



<button style="name:button;background-color:green;width:50;height:50" onclick="button.style.background-color='Blue'">button 1</button>


Thanks

zeero
Jan 5th, 2011, 09:11 PM
OK, I spent way too much time with this today. Evidently you need to add the return false and use "this" for the reference.



<button style="background-color:lightgreen;width:50;height:50" onclick="this.style.backgroundColor='red'; return false;">button 1</button></td>