I have an ASP.NET CheckBoxList:
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Width="10%">
<asp:ListItem Selected="True" Value="1">White</asp:ListItem>
<asp:ListItem Selected="False" Value="2">Black</asp:ListItem>
<asp:ListItem Value="3">Red</asp:ListItem>
<asp:ListItem Value="4">Green</asp:ListItem>
<asp:ListItem Value="5">Blue</asp:ListItem>
</asp:CheckBoxList>
I need to modify/delete a particular label of a particular CheckBox in a CheckBoxList:
The following code is working fine for the CheckBox value, however it is not working for the CheckBox label.
var CheckBoxListInputValue = 3; //value may be dynamic
var CheckBoxListInputInnerHTML = "Red"; //value may be dynamic
$("#CheckBoxList1 label[innerHTML =" + CheckBoxListInputInnerHTML + "]").remove(); //Not working
$("#CheckBoxList1 :input[value = " + CheckBoxListInputValue + "]").remove(); //Working
BTW, I don't want to use any for loop.
asp.net generate a table from your checkboxlist, and in order to remove an option you must remove actually a TR. The following code remove the Red option on your sample then you can change Red with the dynamic value
$('#CheckBoxList1 label').each(function () {
if ($(this).text() == 'Red') {
$(this).closest('tr').remove();
return false;
}
});
Test it here
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