javascript - How to get text from paragraghs while preserving a space at the beginning of each? -


example:

<div id="input-content">   <p>1 2 3</p>   <p>4 5 6 7</p> </div> 

if do:

$("#input-content").text(); 

i get:

"1 2 34 5 6 7" 

how can

"1 2 3 4 5 6 7" 

instead?

one possible way texts in array , join elements ' ' separator:

$('#input-content > p').map(function() {     return $.text(this); }).get().join(' '); 

demo: http://jsfiddle.net/y25yg/


Comments

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -

collision detection - C++ library for mesh to mesh intersection: what is available? -