我知道 $fn.insertAfter()
用于在作为参数提供的元素之后插入元素。 $fn.after()
与它有何不同?
最佳答案
$.fn.after()
help在您调用的目标元素之后插入一个元素。
$('div').after('<div>new div</div>');
然而,$.fn.insertAfter
在您指定的节点之后插入 target 元素:
$('<div>new div</div>').insertAfter($('#someid'));
后者通常是首选,因为您可以保留对新创建的元素的引用,并且可以在其上链接更多方法。例如:
$('<div>new div</div>')
.insertAfter($('#someid'))
.attr('foo', 'bar')
.css({
'background-color': 'red'
});
是可能的。你不能用 .after()
help 来做到这一点。 .append()
help 也是如此。/.appendTo()
help和 .insertBefore()
help/.before()
help
关于javascript - $fn.insertAfter() 和 $fn.after() Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4971477/