jQuery: When creating a new element, do I need the ending tag?

前端 未结 4 1806
面向向阳花
面向向阳花 2021-01-02 01:54
var $div = $(\'
\').appendTo($(\'#header\'));

When creating new elements and adding them to the DOM, do you need the endi

4条回答
  •  耶瑟儿~
    2021-01-02 02:28

    You always need the ending tag to have proper html.

    But it is a fact that the majority of browsers let such mistakes slip. It's no reason to be lazy, though, you should not rely on the browsers' tolerance for your code to work. This tolerance is there to be able to display sites with a few mistakes, not to caution deliberately incorrect code.

提交回复
热议问题