jquery - How to get nth-child number of a element -


I do not need the .index () value.

For example. When I have a list:

  & lt; Ul & gt; & Lt; Li class = "alpha" & gt; & Lt; / li & gt; & Lt; Li class = "alpha" & gt; & Lt; / li & gt; & Lt; Li class = "alpha" & gt; & Lt; / li & gt; & Lt; li class = "beta" & gt; & Lt; / li & gt; & Lt; li class = "alpha" & gt; & Lt; / li & gt; & Lt; Li class = "beta" & gt; & Lt; / li & gt; & Lt; li class = "beta" & gt; & Lt; / li & gt; & Lt; li class = "alpha" & gt; & Lt; / li & gt; & Lt; li class = "beta" & gt; & Lt; / li & gt; & Lt; li class = "beta" & gt; & Lt; / li & gt; & Lt; / Ul & gt;   

I need to get the order number of each class, and the index count is to ignore the second class in the list, so I need something that should work like this:

  JQ ('ul li'). No ('beta'). Get each (function () {jQuery (this) .text (nth-child (this number) here;});   

and then the result will be

  & lt; Ul & gt; & Lt; Li class = "alpha" & gt; 1 & lt; / li & gt; & Lt; Li class = "alpha" & gt; 2 & lt; / li & gt; & Lt; Li class = "alpha" & gt; 3 & lt; / li & gt; & Lt; Li class = "beta" & gt; & Lt; / li & gt; & Lt; Li class = "alpha" & gt; 4 & lt; / li & gt; & Lt; Li class = "beta" & gt; & Lt; / li & gt; & Lt; Li class = "beta" & gt; & Lt; / li & gt; & Lt; Li class = "alpha" & gt; 5 & ​​lt; / li & gt; & Lt; Li class = "beta" & gt; & Lt; / li & gt; & Lt; Li class = "beta" & gt; & Lt; / li & gt; & Lt; / Ul & gt;   

I can do the same with other classes like:

  jQuery ('ul li'). No ('alpha'). Get each (function () {jQuery (this) .text (nth-child (this number) here;});   

And this is the result

    

Please

every The function has an index value:

  jQuery ('ul li'). No ('beta'). Each (function (index) {var count = index + 1; jquery (this) .text (count);});    

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 -