DelphiLynx
DelphiLynx

Reputation: 921

jQuery select <br> tags and wrap spaces around it

For example I have this markup:

Test text<br>
test2 text

That
inside it needs to have a space before, and after. Like this

" <br> " 

So I can split the whole text and get a complete list like this:

Test
text
<br>
test2
text

I do the splitting with this code:

var words = text.split(" ");
    //            console.log("words:" + words);
for ( var i = 0, l = words.length; i<l; ++i ) {
    //  console.log(i +": "+words[i] );
}

I have some code to answer my question. Not complete yet, I need your help.

// Replace all "<br>" to " <br> "             
$("#artikel br").each(function(){
   alert($(this).index()));
});

Upvotes: 0

Views: 609

Answers (1)

gdoron
gdoron

Reputation: 150253

$("#artikel").html(function(index, oldhtml){
    return oldhtml.replace(/\<br\>/gi, "&nbsp;<br>&nbsp;"); 
});

html docs

Live DEMO

Upvotes: 1

Related Questions