How to select individual cell instead of the whole role?

How to select individual cell instead of the whole role?

menkey18menkey18 Posts: 12Questions: 0Answers: 0
edited July 2011 in General
Hi, I am wondering if there is a way to select individual cells in a role instead of the whole role.

Here is the code I used to select a row:

[code]
$('#example tr').live('click', function() {
if ( $(this).hasClass('row_selected') )
$(this).removeClass('row_selected');
else
$(this).addClass('row_selected');
} );
[/code]

I tried to change 'tr' to 'td' or change from 'row_selected' to 'select'.
It doesn't seem to work.

Cheers.

Replies

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    [code]
    $('#example tbody td').live('click', function() {
    if ( $(this).hasClass('cell_selected') )
    $(this).removeClass('cell_selected');
    else
    $(this).addClass('cell_selected');
    } );
    [/code]

    should work. You'd need a "cell_selected" class of course to highlight the cell...

    Allan
  • menkey18menkey18 Posts: 12Questions: 0Answers: 0
    Hi Allan,

    I tried your code but doesn't seem to be working. I have added the following codes into the CSS, but the table doesn't seem to be selectable.

    [code]

    table.display td.even.cell_selected td {
    background-color: #B0BED9;
    }

    table.display td.odd.cell_selected td {
    background-color: #9FAFD1;
    }

    [/code]

    Is this right?
  • menkey18menkey18 Posts: 12Questions: 0Answers: 0
    edited July 2011
    Hi Allan, I got it sorted, here is the correct CSS code:

    [code]

    table.display tr.even td.cell_selected {
    background-color: #B0BED9;
    }

    table.display tr.odd td.cell_selected {
    background-color: #9FAFD1;
    }

    [/code]
This discussion has been closed.