Horje Website
Filtering the Selection of Elements in jQuery via Function – Learn Filter elements selection through a custom function – jQuery Code

Filtering the Selection of Elements in jQuery via Function – Learn Filter elements selection through a custom function

Filtering the Selection of Elements in jQuery via Function - Learn Filter elements selection through a custom function - jQuery Code


 
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Filtering the Selection of Elements in jQuery via Function</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").filter(function(index){
  15. return index % 2 !== 0;
  16. }).addClass("highlight");
  17. });
  18. </script>
  19. </head>
  20. <body>
  21.     <h2>Unordered List</h2>
  22. <ul>
  23. <li>First list item</li>
  24. <li>Second list item</li>
  25. <li>Third list item</li>
  26. <li>Fourth list item</li>
  27. </ul>
  28.     <hr>
  29.     <h2>Another Unordered List</h2>
  30.     <ul>
  31. <li>First list item</li>
  32. <li>Second list item</li>
  33. <li>Third list item</li>
  34. <li>Fourth list item</li>
  35. </ul>
  36. </body>
  37. </html>



Try Your Self ->



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

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