We have list in html:
<ul class="list">
<li>some text<li>
<li>some text<li>
<li>some text<li>
<li>some text<li>
<li>some text<li>
...
<li>some text<li>
</ul>
There can be more than 100 <li>
How to do:
1) Add for each <li> id with number, like:
<li id="item1">some text<li>
<li id="item2">some text<li>
...
<li id="item200">some text<li>
and so on, to the end.
2) Count all <li> inside <ul class="list">
3) After second step, if there are more than 60 <li>, add their IDs (item number) to array 1, all other’s <li> IDs add to array 2 (from 60 to the end, from 60 to 500 if there are 500 <li>).
Thanks!
Step 1:
Step 2:
Step 3:
EDIT: Mis-spelled
function. Fixed.Note: Of course, you don’t need a
countvariable.$li.lengthcan go inside theif()statement.Note: The
.slice()method will return a jQuery object. If you actually want an array, add.get()after.slice(). Or with jQuery 1.4 or later, you can use.toArray().