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 :)
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
Post a Comment