Posted By

bullzito on 04/03/11


Tagged

select-manipulate-elements-index-after-traverse


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

bullzito


Select/Traverse based on Length of Elements


 / Published in: JavaScript
 

URL: http://marioluevanos.com/playground/Select%20Lenght%20of%20Elements/

Useful if you want to manipulate/style/remove items after a given index count.

  1. //HTML
  2. <div>Index 0</div>
  3. <div>Index 1</div>
  4. <div>Index 2</div>
  5. <div>Index 3</div>
  6. <div>Index 4</div>
  7.  
  8.  
  9. //SCRIPT
  10. $(document).ready(function(){
  11.  
  12. //get the number of DIV's
  13. var divCount = $('div').length;
  14.  
  15. //check to see if the count is greater than 3
  16. if (divCount > 3) {
  17.  
  18. //count starts at zero (0, 1, 2...)
  19. $('div:gt(2)').css('background','darkOrange');
  20.  
  21. }
  22.  
  23. });//jQuery

Report this snippet  

You need to login to post a comment.