jQuery – Odd and Even Selector

Today’s success… using jQuery’s even selector to save time on making a list of museums stand apart from one another.


$(function(){$(“ul.museumList li:even”).addClass(“blue”);});

Before :even


After :even


It’s just a little thing, but it makes a big difference when implementing the D.R.Y (don’t repeat yourself) principle. One thing to note, if JavaScript is disabled on your user’s browser, this will disappear. However, it’s mostly for aesthetics and not accessibility, so it’s not something I would worry about.


One Reply to “jQuery – Odd and Even Selector”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s