469,270 Members | 1,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Changing background color with javascript

Hi'

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>
  15.  
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 1895
dmjpro
2,476 2GB
write down .....

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

kind regards.
dmjpro.
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.