Creating an empty element with start tag vs. self closing tag

前端 未结 3 1751
一整个雨季
一整个雨季 2021-01-11 10:40

In jQuery, is there any difference between this:

$(\'
\').appendTo(\'body\');

And this:

$(\'
\').appe
3条回答
  •  情书的邮戳
    2021-01-11 11:28

    No. Neither this $("

    ") nor this $("
    ") will cause problems.

    The proof is so that if we go to jQuery sources we can see that in case of selector with single tag syntax <...> it parses selector with this regular expression:

    rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/
    

    where only the symbolic part is used for createElement and closing slash can be optional.

提交回复
热议问题