Hide Checkbox and Label based on Label text
-
09-12-2019 - |
Question
The label text of a checkbox is dynamically generated in CodeCharge. The label text includes the amount of available articles. When this number is (0), the checkbox and the label text should be hidden, if not both checkbox and label value must be shown.
In this case checkbox and label text hidden:
<input id="i_search_2_newdatad9_1" name="d9[]" value="standplaatsreis" type="checkbox" /><label for="i_search_2_newdatad9_1">Standplaatsreis (0)</label>
In this case checkbox and label visible:
<input id="i_search_2_newdatad9_1" name="d9[]" value="standplaatsreis" type="checkbox" /><label for="i_search_2_newdatad9_1">Standplaatsreis (8)</label>
I appreciate your suggestions for a php or jquery script.
Solution
A jQuery solution:
$('label:contains("(0)")').each(function() {
$('#' + $(this).attr('for')).hide();
$(this).hide();
});
OTHER TIPS
Since you mention jQuery in your question:
$(function() { $('input').filter(function() { return $(this).next('label').text().substr(-3) == '(0)'; }).hide().next('label').hide(); }); });
A PHP solution would be better, but without any code, we cannot help you.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow