I have the following html structure. I can select the the <li> but cannot get the checkbox value - it's undefined
<ul>
<li class="selected" style="false">
<label class="">
<input type="checkbox" data-name="selectItem" value="2447">
<span>England</span>
</label>
</li>
</ul>
$('ul li.selected').each(function () {
console.log('li.selected');
var val = $(this).closest('label').find('[type=checkbox]').val();
console.log(val);
});
closest() goes up the DOM, you should use find() as you want to go down instead. Also note that you can achieve what you require in a single call to find(). Try this:
$('ul li.selected').each(function () {
var val = $(this).find('label :checkbox').val();
console.log(val);
});
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