In which case it is better to use the .append(), and which .appendTo()?

前端 未结 7 718
长情又很酷
长情又很酷 2021-01-12 04:48

There is no big difference between those functions except the syntax:

$(\'.target\').append(\'text\');
$(\'text\').appendTo(\'.target\');

A

7条回答
  •  天涯浪人
    2021-01-12 05:16

    When you are creating an element, it's smoother to use .appendTo equivalents

    $("
    ", {text: "hello"}).appendTo("body");

    vs

    $("body").append( $("
    ", {text: "hello" }) /*Awkward having to call jQuery constructor here*/);

提交回复
热议问题