Horje Website
Selecting an Element by Negative Index in jQuery – Learn Select element by negative index – jQuery Code

Selecting an Element by Negative Index in jQuery – Learn Select element by negative index

Selecting an Element by Negative Index in jQuery - Learn Select element by negative index - jQuery Code


 
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Selecting an Element by Negative Index in jQuery</title>
  6. <style>
  7. .highlight{
  8. background: yellow;
  9. }
  10. </style>
  11. <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  12. <script>
  13. $(document).ready(function(){
  14. $("ul li").eq(-2).addClass("highlight");
  15. });
  16. </script>
  17. </head>
  18. <body>
  19.     <h2>Unordered List</h2>
  20. <ul>
  21. <li>First list item</li>
  22. <li>Second list item</li>
  23. <li>Third list item</li>
  24. <li>Fourth list item</li>
  25. </ul>
  26.     <hr>
  27.     <h2>Another Unordered List</h2>
  28.     <ul>
  29. <li>First list item</li>
  30. <li>Second list item</li>
  31. <li>Third list item</li>
  32. <li>Fourth list item</li>
  33. </ul>
  34. </body>
  35. </html>



Try Your Self ->



Published:
September 16, 2020
Author:
admin
Category:
jQuery Advanced, jQuery Source Code
Views:
21

This article was posted in jQuery Advanced, jQuery Source Code and tagged , , . Bookmark the permalink. Follow comments with the RSS feed for this post.Post a Comment or leave a trackback: Trackback URL.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Horje © 2011 - 2023