Hi I have a div element that contains a list of checkboxes like this
<ul>
<li><input type="checkbox" ID="check1" /><label for="check1">Monday</label></li>
<li><input type="checkbox" ID="check2" checked="checked"/><label for="check2">Tuesday</label></li>
<li><input type="checkbox" ID="check3" /><label for="check3">Wednesday</label></li>
<li><input type="checkbox" ID="check4" checked="checked"/><label for="check4">Thursday</label></li>
</ul>
I want to get the values checked in a string like 'Tuesday-Thursday'. So I wrote this very concise jQuery instruction
$('input:checked', 'ul').next().text()
This give me 'TuesdayThursday'. I could not find the way to pass a separator and have 'Tuesday-Thursday'
Try something like
$('input:checked', 'ul').map(function(){
return $(this).next().text();
}).get().join('-');
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