jQuery, get html of a whole element [duplicate]

You can clone it to get the entire contents, like this: var html = $(“<div />”).append($(“#div1″).clone()).html(); Or make it a plugin, most tend to call this “outerHTML”, like this: jQuery.fn.outerHTML = function() { return jQuery(‘<div />’).append(this.eq(0).clone()).html(); }; Then you can just call: var html = $(“#div1”).outerHTML();

Selecting empty text input using jQuery

Another way $(‘input:text’).filter(function() { return $(this).val() == “”; }); or $(‘input:text’).filter(function() { return this.value == “”; }); or // WARNING: if input element does not have the “value” attribute or this attribute was removed from DOM then such selector WILL NOT WORK! // For example input with type=”file” and file does not selected. // It’s … Read more

How to know when all ajax calls are complete

The easy way The easiest way is to use the .ajaxStop() event handler: $(document).ajaxStop(function() { // place code to be executed on completion of last outstanding ajax call here }); The hard way You can also manually detect if any ajax call is still active: Create a variable containing number of active Ajax connections: var … Read more