Invoking a jQuery function after .each() has completed

In jQuery, is it possible to invoke a callback or trigger an event after an invocation of .each() (or any other type of iterative callback) has completed. For example, I would like this “fade and remove” to complete $(parentSelect).nextAll().fadeOut(200, function() { $(this).remove(); }); before doing some calculations and inserting new elements after the $(parentSelect). My … Read more

Access a variable outside the scope of a Handlebars.js each loop

I have a handlebars.js template, just like this: {{externalValue}} <select name=”test”> {{#each myCollection}} <option value=”{{id}}”>{{title}} {{externalValue}}</option> {{/each}} </select> And this is the generated output: myExternalValue <select name=”test”> <option value=”1″>First element </option> <option value=”2″>Second element </option> <option value=”3″>Third element </option> </select> As expected, I can access the id and title fields of every element of myCollection … Read more

How do I loop through or enumerate a JavaScript object?

I have a JavaScript object like the following: var p = { “p1”: “value1”, “p2”: “value2”, “p3”: “value3” }; Now I want to loop through all p elements (p1, p2, p3…) And get their keys and values. How can I do that? I can modify the JavaScript object if necessary. My ultimate goal is to … Read more