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.

Code:

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

Before :even

before

After :even

after

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.

Advertisements

One thought on “jQuery – Odd and Even Selector

  1. Pingback: CSS3: nth-child selector | Carney Develop It

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s