Attached/Detached
Returns whether or not an element is attached or detached from the DOM
HTML
<div id="attached">Vinay</div>
JavaScript
(function($) {
$.extend({
attached: function(elem) {
if (elem instanceof jQuery) {
elem = elem[0];
}
return $.contains(elem.ownerDocument.documentElement, elem);
},
detached: function(elem) {
}
});
})(jQuery);
jQuery(function($) {
var $att = $("#attached"),
$div = $("<div>");
console.log("#attached is attached?", $.attached($att));
console.log("div is attached?", $.attached($div));
console.log("div is detached?", $.detached($div));
$att.append($div);
console.log("div is attached?", $.attached($div));
});