jquery - Alternative color class after first elements -


I have to add a class that will list the style list differently because I have more than one list on one page And I need to restart the style for each list, but I have decided to look at each list.

  $ ('ul.myList'). Each (function) {$ ('Li: visible: even: no (.red, .green)'). AddClass ('newStyle');});   

Some items are hidden and need to drop the top two items in each list.

  & lt; Ul & gt; & Lt; Li class = "red" & gt; ... & lt; / li & gt; & Lt; Li class = "blue" & gt; ... & lt; / li & gt; & Lt; Li & gt; ... & lt; / li & gt; & Lt; Li & gt; ... & lt; / li & gt; & Lt; li class = "hidden" & gt; ... & lt; / li & gt; & Lt; Li & gt; ... & lt; / li & gt; & Lt; / Ul & gt; & Lt; Ul & gt; & Lt; Li class = "red" & gt; ... & lt; / li & gt; & Lt; Li class = "blue" & gt; ... & lt; / li & gt; & Lt; li class = "hidden" & gt; ... & lt; / li & gt; & Lt; li class = "hidden" & gt; ... & lt; / li & gt; & Lt; Li & gt; ... & lt; / li & gt; & Lt; Li & gt; ... & lt; / li & gt; & Lt; Li & gt; ... & lt; / li & gt; & Lt; Li & gt; ... & lt; / li & gt; & Lt; / Ul & gt;   

For some reason it seems that strange / counting continues from one list to another. What am I missing?

P.S. Here I have used To give an idea, here is actually hidden in many different ways.

If you want to "restart" any / weird count then li needs to specify a reference point to the selector You can use .find () to select descendent elements. $ ('ul.myList') Each (function () {$ (this). Find ('li: is visible: even: no (.red, .green) '). addClass (' newStyle ');});

refers to $ (this) special ul in the above reference you are currently running in <.> .each ()

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -