How to change the value on attribute in html using javascript

Posted on 2010-01-12
Medium Priority
Last Modified: 2013-11-18
I got the following line of code in html which create a table:

                  <td id="Q6Cell0ID" class="matrixCellBorder" bgcolor="#FFFFFF">&#160;</td>

How using a click of a button to execute a javascript function, I want to change the value of bgcolor from "#FFFFFF" to "#FF0000". To do this I am trying to use the following line in javascript


I get no javascript errors, but the back ground colour doesnt change. Any suggestions???
Question by:dipster307
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26293216
try this

LVL 22

Accepted Solution

kadaba earned 2000 total points
ID: 26293704

The bgcolor is deprecated.
so avoid using that.
You can use as shown in the code attached.

<script type="text/javascript">
function changeTDColor(tdId,tdColor){
	document.getElementById(tdId).style.backgroundColor = tdColor;	

<table width="100%">
		 <td id="Q6Cell0ID" class="matrixCellBorder" bgcolor="#FFFFFF">&#160;</td>
		 <td><input type="button" value="change color of adjacent TD" onclick="changeTDColor('Q6Cell0ID','#FF0000');"></td>

Open in new window


Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question