How do I get the tristate jquery plugin to check the hidden input?
-
13-06-2021 - |
Question
I have been working for a client that is using the tristate jquery plugin and after a bunch of debugging I have found that the hidden input is not showing up:
<ul>
<li>
<a href="#" class="checkbox checked">undefined</a>
<input type="checkbox" style="display: none; " />
<label for="england" class="checkbox">England</label>
<span class="toggler opened"> </span>
<ul style="display: block; ">
<li class="city">
<a href="#" class="checkbox checked">undefined</a>
<input type="checkbox" value="leeds" id="cb_leeds" style="display: none; " />
<label for="cb_leeds" class="checkbox" >Leeds</label>
</li>
<li class="city">
<a href="#" class="checkbox checked">undefined</a>
<input type="checkbox" value="london" id="cb_london" style="display: none; " />
<label for="cb_london" class="checkbox checked" >London</label>
</li>
</ul>
</li>
</ul>
I found that in the plugin that they are using they have this in their script:
$('#pf-locations .city input:checked').each(function() {
cities.push($(this).val());
});
Anyone know how I can get the plugin to check the hidden input? Thanks!
Solution
You can try this:
$('#pf-locations .city label.checked').each(function() { // keeping ref of label
cities.push($(this).prev(':checkbox').val()); // using label ref get input value
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow