By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 2,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

Changing background color with javascript

P: 89
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
Share this Question
Share on Google+
1 Reply


dmjpro
100+
P: 2,476
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.