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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With