Using Delegate and Undelegate in jQuery

Using delegate and undelegate in jQuery, you can bind or remove a handler from the event for all elements that matches the current selector. Basically, these methods achieve the same thing as the jQuery .live() and .die() methods but they just use a different syntax. Syntax of Delegate: $(selector).delegate(childSelector,event,data,function) Example of jQuery Delegate: $(“table”).delegate(“td”, “hover”, […]

Include multiple js files using jQuery $.getScript() method

The jQuery getScript() method is used to Include multiple js files i.e. load and execute a JavaScript from the server using an AJAX HTTP GET request. The method returns XMLHttpRequest object and the callback is fired once the script has been loaded, but not necessarily executed. Syntax of getScript: $(selector).getScript(url,success(response,status)) $.getScript( “test.js”, function( data, textStatus, […]

.empty() vs .remove() vs .detach() – jQuery

jQuery provides various methods to remove elements from DOM i.e. .empty(), .remove() and .detach(). So lets find out the difference between jQuery .empty(), .remove() and .detach() method. .empty(): jQuery .empty() method removes all the child element of the matched element where remove() method removes set of matched elements from DOM. $( “.content” ).empty(); remove(): jQuery […]

jQuery post() Method – load data from the server

jQuery post() Method loads data from the server using a HTTP POST request. Syntax: $(selector).post(URL, data, function(data,status,xhr), dataType) Example of jQuery post(): $.post( “ajax-master.php”, function( data ) { $( “#result” ).html( data ); }); The above example fetches the requested HTML snippet and inserts it on the page based on ID. Read also: Abort Ajax […]

Abort Ajax requests using jQuery

Using jQuery abort() you can cancel a running AJAX request forcefully before it ends as this hits several times within a short time period. This is usually in cases where the user might perform an action, based on AJAX request several times within a short time period. For example, There is a auto-complete functionality for […]