Skip to content Skip to sidebar Skip to footer

How To Strip Out
Tags And Wrap Lines With

And

Tags?

This is what the HTML code looks like. I need to strip out the br tags and wrap the lines in paragraph tags (ie the lines with dates). Each date should be wrapped in its own para

Solution 1:

Edit: By using <p> tags in that manner your runining it's whole purpose instead you should try removing the <br> tags and placing the text inside <p> elements, which will have the same effect but will be semantically correct.

Edit2: I think you wanted it in the above way, just triple read your question and I think I gotcha!

var $p = $('.details p');
$p.contents()
  .filter(function() { returnthis.nodeType == 3; }) // Select all textnodes
  .wrap('<p>') // Place them inside paragraph elements

$('br', $p).remove(); // Remove all break elements

Working fiddle:http://jsfiddle.net/garreh/UWDw5/1/

Post a Comment for "How To Strip Out
Tags And Wrap Lines With

And

Tags?"