Posts

Showing posts with the label jQuery

jQuery can be unbelievably handy and concise

Adding selectable table rows in jQuery The short bit of jQuery consists of the following: Adds a .click() function to any tr elements inside a tbody element to toggle the addition of the selected class whenever a row is clicked. Next, another .click() to give a link with the ID selectAll the ability to toggle all rows at once. Finally, one more .click() attached to the ID clearSelected that will deselect any rows currently selected. In this case any tr elements inside a tbody element are selected, but this could be refined using IDs or Classes if there are multiple tables on the page. $( document ).ready( function () { $( 'tbody tr' ).click( function () { $( this ).toggleClass( 'selected' ); }); $( '#selectAll' ).click( function () { $( 'tbody tr' ).toggleClass( 'selected' ); }); $( '#clearSelected' ).click( function () { $( 'tbody tr' ).removeClass( ...