1$.each(array, function(key, value) {
2 if(value === "foo") {
3 return false; // breaks
4 }
5});
6
7// or
8
9$(selector).each(function() {
10 if (condition) {
11 return false;
12 }
13});
1var arr = ['one','two','three','four','five'];
2$.each(arr, function(index, value){
3 console.log('The value at arr[' + index + '] is: ' + value);
4});
1$( "li" ).each(function( index ) {
2 console.log( index + ": " + $( this ).text() );
3});
1//looping through list elements in jquery
2$('#myUlID li').each(function() {
3 console.log($(this));
4})
1$( "li" ).each(function( index ) {
2 console.log( index + ": " + $( this ).text() );
3});
4
1$(".demo").each(function() { // parse each .demo element
2document.write($(this).text() + "\n"); // output their text
3});
4