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

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

In jQuery, is there any difference between this:

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

And this:

$(\'
\').appe
3条回答
  •  攒了一身酷
    2021-01-11 11:24

    That syntax will not cause problems as long as nothing comes after it.

    $("
    ") // Ok! $("
    foobar") // Not Ok! $("

    ") // Not Ok!

    For reference, see http://api.jquery.com/jQuery/#jQuery2

提交回复
热议问题