jquery - array from select children span text separated by commas [resolved] -


i need generate array in jquery:

one,two,three,four 


selecting text multiple <span> children:

<div id="group">     <div><input value="somevalue"/><span>one</span></div>     <div><input value="somevalue"/><span>two</span></div>     <div><input value="somevalue"/><span>three</span></div>     <div><input value="somevalue"/><span>four</span></div> </div> 


i've tried this:

$('html').find('#group span').text(); 

but joins text no spaces:

onetwothreefour 


need separate text commas


many generous :)

working demo

try use .map() along .get() collect values in array, afterwards .join() array character want.

var text = $('#group span').map(function(){      return $(this).text();  }).get().join(); 

demo

side note: default .join() join text using ,. there no need specify in our case.


Comments

Popular posts from this blog

Unable to open serial port using Putty to bluetooth device on windows 7 64 bit -

bash - How do you programmatically add a bats test? -

java - Getting exception in JDBC thin driver -