A Geek's Cogitations, Conjectures and other Cortical Experiences

Tag: Snippets

Snippets: [jQuery] Highlight Rows with Checkbox

It has been a while since I have posted a new jQuery snippet, mostly because I only get to play with jQuery once in a while (though I wish I could use it more). Recently I had to create an administration page for deleting multiple rows of data. I presented the data in a gridview using checkboxes as the control for selecting which items will be deleted. I wanted to make it clear which items were going to be deleted so, using jQuery, I wrote the following snippet to accomplish what I wanted.

Obviously you will need to define a CSS class called “highlight”. I think the best thing about this snippet of code is that it will work if you are using a standard HTML table to organize your data or you are using a GridView object in ASP .NET. This snippet will also ignore the row that contains the “Select All” checkbox; for my purposes the select all checkbox was in the header of the table/grid.


$('#SurveyGrid input:not(#selectAll)').click(function () {
if ($(this).attr("checked") == true) {
$(this).parent().parent().addClass('highlight');
} else {
$(this).parent().parent().removeClass('highlight');
}
});

I have posted this code on snipplr.com (as usual).

Snippets: [JQuery] Toggle Expand/Collapse

I have posted a new snippet on Snipplr. It’s another jQuery snippet that handles the expand and collapse of a div (or span) section. The idea for this snippet is that the user would click a plus (+) image, the code would display the hidden section and change the image to a minus ( – ). The reverse, of course, would happen if the user were to click the minus.

Here is the snippet:

The #img and #div should match the ID attribute of the page elements the code needs to respond to.

You can see this and more of my code snippets at Snipplr.

Happy Coding!

Powered by WordPress & Theme by Anders Norén