Which is the correct or better way to create a new element with jQuery?

后端 未结 4 1689
名媛妹妹
名媛妹妹 2021-02-05 19:48

Related to the answer https://stackoverflow.com/a/10619477/1076753 to cleate an element is better to use

$(\"
\", {id: \"foo\", class: \"a\"});
4条回答
  •  离开以前
    2021-02-05 20:28

    If you go solely by metrics that can be easily measured: The first is better because it is 2 bytes shorter.

    Once you start accounting for readability and other less tangible considerations, it becomes largely a matter of opinion.

    So, at the end it's wrong to use one of the first two options for a div?

    No, that section only applies "If the HTML is more complex than a single tag without attributes"

提交回复
热议问题