Posted By

jasonseney on 11/03/09


Tagged

javascript jquery


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

konpao


Loop on jQuery object and return value


 / Published in: JavaScript
 

Returning a boolean inside of jQuery's $.each() function will only break the loop. To get a return value, you can convert the jQuery object to array and use a regular for loop in javascript.

  1. var checkBoxes = $(':checkbox');
  2.  
  3. var allAreSelected = (function() {
  4.  
  5. for (i in checkBoxes.get()) {
  6. if (!checkBoxes[i].checked) {
  7. return false;
  8. }
  9. }
  10.  
  11. return true;
  12.  
  13. })();

Report this snippet  

You need to login to post a comment.