471,893 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,893 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 1984
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

Post your reply

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

Similar topics

14 posts views Thread by Holden Caulfield | last post: by
1 post views Thread by P.Singh | last post: by
13 posts views Thread by mike | last post: by
8 posts views Thread by Bosconian | last post: by
2 posts views Thread by paul | last post: by
reply views Thread by YellowAndGreen | last post: by

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.