473,389 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 software developers and data experts.

Changing background color with javascript


I have a problem with changing the background color in a table cell when i click on the content in the cell.

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var ie = document.all
  3. var ns = document.getElementById && !ie
  4. function rowclick(e) {
  5. var obj = ns ? e.target : event.srcElement
  6. if (obj.id=="click") {
  7. obj.style.background="#ff0066"
  8. obj.onblur=function() {
  9. obj.style.background="#F7F4EC"
  10. }
  11. }
  12. }
  13. document.onclick=rowclick
  14. </script>
And i call it by using:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" id="click">Some text</a>
Now, this works fine. The background changes when i click the cell content.

The real problem is that i have cells with two different original background colors.

How do i do this, so that the original background returns when clicking another content in another cell with different background.........?
May 25 '07 #1
1 2079
2,476 2GB
write down .....

Expand|Select|Wrap|Line Numbers
  1. obj.style.setAttribute("backgroundcolor","#color_hex_value");
best of luck.

kind regards.
May 25 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: John D | last post by:
I am trying to change the background colour of either a div or a textarea with javascript, but am having problems. I have passed a hex colour value in the variable hval, and with the following...
by: Holden Caulfield | last post by:
Hi there, for IE 5+ I need to be able to change certain TD tagsī background colors, and canīt figure out how to do it... For instance, in a table with 25 cells, somewhere between 5 or 10 will...
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
by: P.Singh | last post by:
hi all i am designing a website for a charity origanisation. they cater towards the senior crowd. i would like to have choice by which the user can change the background as required (like...
by: Arthur Shapiro | last post by:
I'm the webmaster for a recreational organization. As part of one page of the site, I have an HTML "Calendar at a Glance" of the organization's events for the month. It's a simple table of a...
by: mike | last post by:
I have some elements that I want to change color when I mouse over them and them back on mouse off. I'd like the color to remain with "#c7d0e0" when the user clicks on them. <td...
by: Bosconian | last post by:
I have two multiple select inputs. Initially the first contains a bunch of items and the second is empty. Using a common method, I move items back and forth by double clicking on them. This...
by: amykimber | last post by:
Hi all, I know I'm doign something really daft, but I can't get this to work... I have a form with a bunch of inputs called ship_owner - why the ? Because I'm submitting this page though php...
by: paul | last post by:
I have a JS function to change the width of a <divthat works great in Firefox, but not at all in IE7. In IE an error message occurs: Line: 92 Char: 5 Error: Invalid Argument Code: 0 Firefox...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.