Results 1 to 2 of 2

Thread: change the background color of the td onclick

  1. #1
    Join Date
    May 2013
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default change the background color of the td onclick

    Hi guys

    I want to change the background colour of the td and also the colour of the link when you click on it.Cna you please help me out

    Developer husain

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,165
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    The simplest way is:

    Code:
    <td onclick="this.style.backgroundColor = 'red';">Whatever</td>
    You can do a link the same way, but a link will usually take you away from a page. So you can use css style instead:

    Code:
    <style type="text/css">
    a:link {background-color: blue;}
    a:active {background-color: red;}
    a:visited {background-color: red;}
    </style>
    Often when someone asks this question they want all tds in the table except the one clicked to be one background color and the clicked one to change to another background color. Is that what you want?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Replies: 0
    Last Post: 01-10-2012, 05:27 PM
  2. Background color change
    By dustnbones in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 05-21-2011, 03:48 PM
  3. Replies: 5
    Last Post: 03-18-2007, 06:00 AM
  4. How to change background color of row onclick?
    By jpaulraj in forum JavaScript
    Replies: 19
    Last Post: 08-14-2006, 03:41 PM
  5. OnClick Change Font color
    By shevi2027 in forum JavaScript
    Replies: 1
    Last Post: 02-20-2006, 03:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •