如何用jquery删除前两个BR标签?
我想用jquery只删除前两个BR标签。
// I want to remove both BR. ...
... ...
我假设这样的事情。 但我不确定。
$('#system br').remove();
有人能告诉我怎么做吗?
使用:lt()
:
$('#system br:lt(2)').remove();
:lt()
采用从零开始的整数作为参数,因此2指的是第3个元素。 所以:lt(2)
是选择元素“小于”第3个。
示例: http : //jsfiddle.net/3PJ5D/
$("#system br:lt(2)").remove();
尝试
$('#system br:first').remove(); $('#system br:first').remove();
第一行删除第一行br
,然后第二行删除第一行,然后再删除第一行。
也试试nth-child。
$("#system > br:nth-child(1), #system > br:nth-child(2)").remove();
删除#system
中的第一个和第二个br实例
此外,如果您只想删除最后一个br,您可以尝试;
$('#elementID br:last').remove();
让我们说br跟随一个 , 你可以试试
$('#elementID strong+br:last').remove();
试试吧。 更换(最多4 BR)至(1 BR)
$('#system br').each(function() { if ($(this).next().is('br')) { $(this).next().remove(); } });
KS FIDDLE