[removed] Whats the difference between 'Document' and 'HTML'

后端 未结 4 1550
一整个雨季
一整个雨季 2021-01-02 16:26

Example:

$(document).click(function() { blah });   
// and
$(\'html\').click(function() { blah });
4条回答
  •  春和景丽
    2021-01-02 16:38

    A few differences I noticed are:

    1. document is a DOM Element which wraps the HTML - DOM Element whereas html is the HTML DOM element.
    2. document includes the first line of the document - the one which specifies the doctype. For ex. (for HTML 5)
    3. HTML can have class, id and other attributes whereas document doesn't have (and can't have) these attributes. Try $(document).addClass('test') v/s $('html').addClass('test'); and notice the difference on the elements tab on developer console.

    Good Luck...

提交回复
热议问题