I'd like to remove only the first two BR tags with jquery.
<div id="system">
<BR CLEAR="ALL"><BR>// I want to remove both BR.
...
<BR>...
...
<BR>
I assume something like this. But I am not sure.
$('#system br').remove();
Could anyone tell me how to do this please?
The line break can be removed from string by using str_replace() function.
jQuery uses: . append(); and . remove(); functions to accomplish this task. We could use these methods to append string or any other html or XML element and also remove string and other html or XML elements from the document.
jQuery remove() Method The remove() method removes the selected elements, including all text and child nodes. This method also removes data and events of the selected elements. Tip: To remove the elements without removing data and events, use the detach() method instead.
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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With