1
<div class="inner">
    line 1
    line 2
    line 3
</div>

$(document).ready(function(){
    $('.inner').wrapInner('<p/>');
});

The current code adds the the <p> tag around all the elements, is it possible to add the <p> to each? like

<p>line 1</p>
<p>line 2</p>
<p>line 3</p>
JJJ
  • 32,902
  • 20
  • 89
  • 102
zadubz
  • 1,281
  • 2
  • 21
  • 36
  • 2
    How are the lines delineated? – T.J. Crowder Mar 21 '12 at 12:39
  • its a list copied from a word document – zadubz Mar 21 '12 at 12:41
  • `@Grundizer`: That doesn't answer the question. In the markup, what makes it clear that a line is a line? Remember that line breaks in HTML are just whitespace, not actual line breaks, except in `pre` elements. – T.J. Crowder Mar 21 '12 at 12:42
  • You'll need to separate each line - http://stackoverflow.com/questions/1155678/javascript-string-newline-character and then wrap each one individually... – Lix Mar 21 '12 at 12:45
  • I'm trying to create a markup that isnt there...the data is given to me in word format there are no line breaks there – zadubz Mar 21 '12 at 12:46
  • You need to Look here http://stackoverflow.com/questions/1726747/jquery-how-do-you-loop-through-each-newline-of-text-typed-inside-a-textarea – Baran Mar 21 '12 at 12:49
  • Is your data coming dynamically? – Nilesh Mar 21 '12 at 12:49

1 Answers1

2

go ahead :

http://jsbin.com/usuciq/edit#javascript,html

var g=$(".inner").html().split(/\n/);

var t= $.map (g,function (a){ if (a!='') return '<p>'+a+'</p>';});

$('.inner').html(t.join(''));
Royi Namir
  • 144,742
  • 138
  • 468
  • 792