2

jQuery uses the script like this:

function remove() {
jQuery("*", this).add([this]).each(function () {
jQuery.event.remove(this);
jQuery.removeData(this);
});
if (this.parentNode)
this.parentNode.removeChild(this);
}

As far as I understand the code is removing the element if the element has parentNode but I wanted to know why does it removes the element which have no parentNode:

$('html').remove();//html has no parentNode but html is removed

Sorry, if I'm one that couldn't understand this script, please make my concept clear. Thank you.

Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
  • See http://stackoverflow.com/questions/3387427/javascript-remove-element-by-id – bjb568 Apr 16 '14 at 07:36
  • 2
    As per my understanding `document` is parent of `HTML` tag. Just try `$('html').parent()` in your browser console – Satpal Apr 16 '14 at 07:36
  • I recommend this blog article: http://www.bennadel.com/blog/1822-learning-jquery-1-4-remove-vs-detach.htm – urbz Apr 16 '14 at 07:37
  • @Satpal but what if $('*').remove(); it removes all, document too???? – Bhojendra Rauniyar Apr 16 '14 at 07:45
  • I have never used `$(document).remove();`, so can't help you on that. Lets see what I can find? EDIT: `$(document).remove();` doesn't remove document. However `$('*').remove();` removes all child element of document but document. In short `document` is never removed – Satpal Apr 16 '14 at 07:46

0 Answers0