Click here to Skip to main content
16,020,459 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I'm writing an app with MVC 4, and I'm dynamically building a table. The table is to be clicked to display things related to the selection in a window below the table.

To show the user which they have selected, I am setting the CSS class on the selected row so that it is styled differently. This works great, BUT I don't know how to reset all the other rows in the table so that there is only the one differently colored row.

Can anyone help?

I thought I could use javascript to iterate through the rows, but I can't figure out how to use this to set the CSS class?

Thanks
Posted

1 solution

Doesn't matter. A case of exhausted brain and hunger.

After some curry, and a few swigs of Red Berry Cider, I realised I was being dumb...

In case anyone else gets logic block on this, here is what I did.

I simply had a variable to contain the item I clicked on so that I can look at it later. Set this during the routine. Then next time I fire the routine, use it to change the old one back to what it should be.

var prevItem;

        $('.update-list-item').click(function (e) {
            if(prevItem != null)
                $(prevItem).removeClass('update-list-item2').addClass('update-list-item');

            prevItem = this;
            $(this).removeClass('update-list-item').addClass('update-list-item2');
        });


I'm off to bed now...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900