select table row

by karin

HTML

<table border="1">
    <tr id="Row1">
        <td>Some label1</td>
        <td>Some complex control1</td>
    </tr>
    <tr id="Row2">
        <td>Some label2</td>
        <td>Some complex control2</td>
    </tr>
    <tr id="Row3">
        <td>Some label3</td>
        <td>Some complex control3</td>
    </tr>
    <tr id="Row4">
        <td>Some label4</td>
        <td>Some complex control4</td>
    </tr>
</table>
<button>move up</button>

JavaScript

$('table tr').on('click', function () {
    $('table tr td').css('background', 'transparent');
    $('table tr').removeClass('selected');
    $(this).children().css('background', 'red');
    $(this).addClass('selected');
});

$('button').on('click', function () {
    var previous = $('.selected').prev();
    $('.selected').after(previous);
});