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

后端 未结 11 662
孤街浪徒
孤街浪徒 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:00

    They are mutual opposites.

    'after' inserts the argument after the selector.

    'insertAfter' inserts the selector after the argument.

    Here is an example of the same thing done with:

    insertafter():

    Greetings

    Hello
    Goodbye
    $( "

    Test

    " ).insertAfter( ".inner" ); Each inner
    element gets this new content:

    Greetings

    Hello

    Test

    Goodbye

    Test

    after():

    Greetings

    Hello
    Goodbye
    $( ".inner" ).after( "

    Test

    " );

    Greetings

    Hello

    Test

    Goodbye

    Test

提交回复
热议问题