How do I change an attribute in an HTML table's cell if I know the row and column index of the cell?

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-04-04T01:38:33Z Indexed on 2010/04/04 1:43 UTC
Read the original article Hit count: 411

Filed under:
|
|

I know nothing about jQuery but am an experienced C++ programmer (not sure if that helps or hurts). I found jQuery code that gives me the row and column index of a cell in an HTML table when a user clicks on that cell. Using such row-column index numbers, I need to change an attribute's value in the previously selected cell and in the cell just clicked. The index numbers are produced and saved with this code:

var $trCurrent = 0; // Index of cell selected when page opens 
var $tdCurrent = 0; // i.e., previously selected cell

$(document).ready(function ()
{
    $("td").click(function ()
    {
        // How toclear previously selected cell's attribute here? ('class', 'recent')
        var oTr = $(this).parents("tr");
        $tdCurrent = oTr.children("td").index(this);

     });
    $("tr").click(function ()
    {
        $trCurrent = $(this)[0].rowIndex;
        // How to set new attributes here? ('class', 'current');
        // and continue work using information from currently selected cell

     });
});

Any help or hints would be appreciated. I do not even know if this is the way I should get the index of the row and column. Thanks.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about tables