All articles tagged as:

jquery

Using jQuery Deferred for long operations

The jQuery $.when() (part of the deferred object) function works great when using the AJAX function since it uses the deferred object by default. What if you want to do something similar when performing asynchronous/synchronous operations by means of regular functions such as? $.when(firstFunction(), secondFunction()).then(function() { console.log('Execute when all functions has completed'); }); Given the scenario above, what if you have a function that takes a little bit longer than the other function such as. /** Create a long operation */ var loadQueue = function() { var dfrQueue…

Read more »

jQuery: Attach events to elements added dynamically via AJAX

I was building a page where there's an image slideshow that would cycle through the images every n-seconds inside a <div> element. Simple enough. Everything was working right until I started moving the HTML elements around and parsing them via AJAX response. In short, the images and its container were being injected into the page dynamically. What I was trying to accomplish was: add the images dynamically including its container <div>, then apply the setInterval() function routine so it can start the cycling process. In most case scenarios such as elements performing CRUD (creat…

Read more »