jquery - How to get nth-child number of a element -
I do not need the For example. When I have a list: 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: and then the result will be I can do the same with other classes like: And this is the result Please .index () value.
& 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;
JQ ('ul li'). No ('beta'). Get each (function () {jQuery (this) .text (nth-child (this number) here;});
& 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;
jQuery ('ul li'). No ('alpha'). Get each (function () {jQuery (this) .text (nth-child (this number) here;});
every The function has an index value:
jQuery ('ul li'). No ('beta'). Each (function (index) {var count = index + 1; jquery (this) .text (count);});
Comments
Post a Comment