Who knew Javascript could be fun?

It gave me migraines till I discovered jQuery. Now I can validate a form with some simple CSS and a couple of lines of jQuery code. And today I had a rather odd requirement to toggle the colour of cells in a table when you click on them. In the old days, I wouldn’t even have attempted this. In my new jQuery heaven, I did this:


(document).ready(function() {
$("td.standard").click(
function(){
var currentclass = $(this).attr("class");
if (currentclass.indexOf("highlightcell") == -1) {
$(this).addClass("highlightcell");
} else {
$(this).removeClass("highlightcell");
}
}
);
});

Voilà!

This entry was posted in Javascript, Web development and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>