James Brooks

Now with pants included

Entries Tagged ‘jquery’

Zebra stripe tables using jQuery

I’ve just noticed that the way I was zebra striping tables in jQuery didn’t handle multiple tables on the same page correctly (for an odd number of rows). Here’s the previous (problematic) snippet:
$(document).ready(function() {
$(’table tbody tr:odd’).addClass(’odd’);
});
The issue was that the use of the jQuery :odd nthChild selector would carry over to multiple tables (they [...]

Make DOM elements hoverable using jQuery

following up the post from earlier today, Make DOM elements hoverable using Prototype, here’s the equivalent javascript code using jQuery instead of Prototype (Uses the same example as in the previous post [a list]).
$(document).ready(function() {
$(’.hoverable > *’)
.mouseover(function() { $(this).addClass(’hover’) })
.mouseout(function() { $(this).removeClass(’hover’) })
});