Color table row if button clicked

I am looking to turn the whole row red in my table when clicked using javascript.

I have managed to turn single cells red with the below code but not the whole tr. Also once the row is red im unable to turn it back to white.

var ie = document.all
var ns = document.getElementById && !ie
function rowclick(e) {
var obj = ns ? : event.srcElement
if (obj.tagName=="TD") {"red"
obj.onblur=function() {"white"

Open in new window

Note that changing if
(obj.tagName=="TD") {
if (obj.tagName=="TR") {
does not work
Who is Participating?
Kyle AbrahamsSenior .Net DeveloperCommented:
fund a nice JS fiddle with JQUery . . . this uses a row click but can be changed to be triggered on the button click and the onblur for the exit:


$(document).ready(function () {
    $('tr').click(function () {
        if( == "" || =="white") {
            $(this).css('background', 'red');
        else {
            $(this).css('background', 'white');

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.