jQuery: What's the difference between after() and insertAfter()

后端 未结 11 688
孤街浪徒
孤街浪徒 2021-01-31 07:42

jQuery has an .after() method, and also an .insertAfter() method.

What\'s the difference between them? I think I can use .after()

11条回答
  •  旧巷少年郎
    2021-01-31 08:13

    They are inverses of each other. As explained in the jQuery documentation:

    This:

    $("p").insertAfter("#foo");
    

    Is the same as this:

    $("#foo").after("p");
    

    And lastly, insertAfter returns all inserted elements, whereas .after() will return the context it is called on.

提交回复
热议问题