JQuery Checkbox class attribute

how do you access the attribute of the <asp:Checkbox> class in a jQuery selector statement?

eg

 <asp:CheckBox runat="server" ID="cbTest" Text="Cb Test" FieldName="1st Test Check Box" class="toggleBox"/> 

 $(':checkbox').toggleAttr("checked", true, false) 

accesses the checkbox and applies a custom function to the checked attribute, but if I want to filter based on a specific class, how do I access / filter based on this?

+4
source share
2 answers

<asp:checkbox> displays as <input type="checkbox" /> . That way you can use an element selector , followed by a chekbox selector , and then a class selector .

 $("input:checkbox.toggleBox") 

will provide you with the desired flag with the class name toggleBox.

See class selector

Note

$(':checkbox') equivalent to $('*:checkbox') , so use $('input:checkbox') instead.

+5
source
 function chkbxch(valor) { //$('.ChChecar input:checkbox').attr('checked', true); $.each($('.Ch' + valor + ' input:checkbox'), function () { if ($(this).attr('checked')) { $(this).attr('checked', false); } else { $(this).attr('checked', true); } }); } 
0
source

Source: https://habr.com/ru/post/1312721/


All Articles