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(' ');
Comments
Post a Comment