James Brooks

Now with pants included

Entries Tagged ‘Javascript’

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’) })
});

Make DOM elements hoverable using Prototype

Here’s a small snippet I use when I want to change style based off of the :hover state of the element. Usually we could just use the :hover pseudo-class (apart from the fact that IE6 will only acknowledge :hover on link tags only). The solution is to use some javascript to add/remove a .hover class on the [...]