Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the first two BR tags with jquery?

Tags:

jquery

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?

like image 409
shin Avatar asked Sep 08 '10 12:09

shin


People also ask

How do you remove a BR tag from a string?

The line break can be removed from string by using str_replace() function.

How remove and append in jQuery?

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.

What is remove in jQuery?

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.


2 Answers

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/

like image 70
Andy E Avatar answered Oct 13 '22 03:10

Andy E


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.

like image 41
BrunoLM Avatar answered Oct 13 '22 03:10

BrunoLM