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

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

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