Change the Background Colour of a Cell using Javascript

Sometimes there may arise a need to change a particular cell's background color. For example, you may want to highlight some particular cell of table, say the "total amount" at the end of the table.

The client-side script in Javascript to highlight a particular cell is given below:


function dt()
{
document.getElementById("tt").style.backgroundColor="yellow";
}


The html page should be appropriately changed. So set the id of the td tag as follows:


<td id="tt">


Now call this javascript function on some event, say button click:


onclick="javascript:dt()


Attachments

  • See Attatched file (18957-20126-test.html)
  • Comments

    Guest Author: Wadje ravi K.02 Jul 2012

    I want to change the background color again when mouse is removed from control. Please suggest me appropriate function in asp.net like "onmouseover".



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: