maccaj51
maccaj51

Reputation: 37

Jquery striped rows

Ive got this script:

$(function(){

  $(".submenu li:even").addClass("oddrow");

});

It works great - but it continues to stripe through all the submenus...

How do i contain it, so it starts again at the start of each submenu

Upvotes: 2

Views: 93

Answers (1)

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76880

You could use a context to restrict the selection (i imagine you have various <ul> that contains your <li>) so that you iterate over the <ul> and then select only the even <li> of that <ul>

$(function(){
   $(".submenu ul").each(function(){
       //provide a context so that it select only `<li>` that are 
       //descendant of that `<ul>` `this` is the current `<ul>`
       $("li:even", this).addClass("oddrow");
   });
});

Upvotes: 2

Related Questions