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

后端 未结 11 847
孤街浪徒
孤街浪徒 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条回答
  •  Happy的楠姐
    2021-01-31 07:58

    It also seems that passing attributes of the inserted element doesn't work with ".insertAfter", but works with ".after"

    works:

    $('#element').after('

    Test

    ', { 'class': 'element_class', 'id': 'element_id' });

    doesn't work:

    $('

    Test

    ', { 'class': 'element_class', 'id': 'element_id' }).insertAfter('#element');

    *edit: seems it doesn't work with ".after" neither, but only with ".appendTo"

提交回复
热议问题