I\'d like to remove only the first two BR tags with jquery.
// I want to remove both BR.
...
<
$("#system br:lt(2)").remove();
Use :lt():
$('#system br:lt(2)').remove();
:lt()
takes a zero-based integer as its parameter, so 2 refers to the 3rd element. So :lt(2)
is select elements "less than" the 3rd.
Example: http://jsfiddle.net/3PJ5D/
Additionally if you only want to remove the last br only you can try;
$('#elementID br:last').remove();
Lets say that the br follows a , you can try
$('#elementID strong+br:last').remove();
Also try nth-child.
$("#system > br:nth-child(1), #system > br:nth-child(2)").remove();
removes first and second instance of br within #system
Try it. Replace (max 4 BR) to (1 BR)
$('#system br').each(function() {
if ($(this).next().is('br')) {
$(this).next().remove();
}
});
KS FIDDLE
Try
$('#system br:first').remove();
$('#system br:first').remove();
The first line removes the first br
, then the second br
becomes the first, and then you remove the first again.