jetlej
jetlej

Reputation: 3392

jQuery find <br/> tags within div and add additional <br/> to each

How can I use jQuery to find all the <br/> tags within a div with class "post" and add an additional <br/> tag after each?

Upvotes: 4

Views: 10605

Answers (2)

Amir Raminfar
Amir Raminfar

Reputation: 34179

Just guessing here but I would try using the .after function like this

$('div.post br').after('<br/>');

Upvotes: 8

krtek
krtek

Reputation: 26607

Try something like this :

$('div.post br').each(function() {
    $(this).after($(document.createElement('br')));
});

But as an advice, you should avoid using <br /> tags in <div> elements. Formatting should be done by CSS, for example you can add a margin-after to your div to have the same result.

Upvotes: 0

Related Questions