cycling through a list of colors with sass

If its possible with pure CSS, its possible with Sass. This will work with any number of colors: http://codepen.io/cimmanon/pen/yoCDG $colors: red, orange, yellow, green, blue, purple; @for $i from 1 through length($colors) { li:nth-child(#{length($colors)}n+#{$i}) { background: nth($colors, $i) } } Output: li:nth-child(6n+1) { background: red; } li:nth-child(6n+2) { background: orange; } li:nth-child(6n+3) { background: yellow; … Read more

Multiple ajax calls inside a each() function.. then do something once ALL of them are finished?

Use deferred objects: $(“#form”).submit(function(e){ e.preventDefault(); var calls = []; $(“.friendName[value!=”]”).each(function(){ // Submit the ajax request calls.push($.ajax({ type: ‘POST’, url: ‘ajax/url’, data: { name: name, email: email }, success: function(json) { // Log a console entry if our ajax request was successful console.log(name + ” was submitted via ajax”); } })); }); $.when.apply($, calls).then(function() { window.location= … Read more

Jquery each – Stop loop and return object

Because when you use a return statement inside an each loop, a “non-false” value will act as a continue, whereas false will act as a break. You will need to return false from the each function. Something like this: function findXX(word) { var toReturn; $.each(someArray, function(i) { $(‘body’).append(‘-> ‘+i+'<br />’); if(someArray[i] == word) { toReturn … Read more