Change color of a table cell using javascript using dropdown menu
Posted
by
Mike Burzycki
on Stack Overflow
See other posts from Stack Overflow
or by Mike Burzycki
Published on 2012-08-28T03:16:24Z
Indexed on
2012/08/28
3:38 UTC
Read the original article
Hit count: 292
I'd like to use some javascript code to change the background color of a single cell within a table.
I have some code below which allows me to change the page background color. This is similar in concept to what I would like to do, but I would really like to be able to change just one cell...not the whole page.
I have thought about making the rest of the cell borders and background colors white, leaving the cell I want to manipulate transparent, but I think this probably a brute force method that will cause me trouble down the road.
Does anyone have any advice to do this with javascript?
The page background color changing code is here:
<form name="bgcolorForm">Try it now:
<select onChange="if(this.selectedIndex!=0)
document.bgColor=this.options[this.selectedIndex].value">
<option value="choose">set background color
<option value="FFFFCC">light yellow
<option value="CCFFFF">light blue
<option value="CCFFCC">light green
<option value="CCCCCC">gray
<option value="FFFFFF">white
</select></form>
Thanks for the help, Mike
© Stack Overflow or respective owner