Reputation: 8413
HTML
<ul>
<li>List 1</li>
<li>List 2</li>
<ul>
jQuery
$('ul li').text();
Current Output
List1List2
Expected Output
List1,List2
Question
How to separate them by comma?
Upvotes: 4
Views: 1691
Reputation: 67207
Try to use .map()
along with .get()
to get that texts into an array and .join()
it afterwards,
var values = $('#tags li').map(function(){
return $(this).text();
}).get().join(','); // List1,List2
Upvotes: 8