jquery - How to add dynamically class to single < li> when using in Loop -


i have created pagination using for-loop, using jquery how add dynamically class < li>. here code:

echo "<ul class='pagination'>"; for($i=1; $i<=$number_of_pages; $i++) {      echo "<li id='add_class'>"."<a href='first_year.php?p=$i'>".$i."</a>";    } echo "</ul>"; 

you can below. consider want add active class

  1. add class first li element

    $("ul.pagination > li:first").addclass("active");

  2. add class nth position element (for example position 5, need pass 4 index)

    $("ul.pagination > li:eq(4)").addclass("active");

  3. if want add class element

    $("ul.pagination > li").addclass("active");


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -