Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap doesn't use "checked" attribute of checkbox

I am using Bootstrap. I have a table with a checkbox in a header and in each collumn. I am trying to make "check all" functionality on jQuery, but it seems that bootstrap does not use checked attribute. As I see, it adds span tag around my checkbox and adds a class 'checked' to it. Is there any possibility to work with checked attr, or I must forget about it and write class checking and switching?

Below goes the part of code from the result HTML:

<td>
  <div class="checker">
    <span class="">
      <input type="checkbox" class="payout_check" style="opacity: 0;">
    </span>
  </div>
</td>

This is unchecked one. The it is checked, third row changes to:

<span class="checked">
like image 372
Bandydan Avatar asked Jun 03 '13 21:06

Bandydan


2 Answers

You could use prop. I faced the same issue. On checking a checkbox, the attribute checked came as undefined. When i changed it to prop, it gave true and false value based on the state of the check box.

$('#checkboxId').prop('checked');
like image 171
Fight code with code Avatar answered Oct 06 '22 01:10

Fight code with code


this work for uncheck

jQuery('span', $('#uniform-You_id_checkbox')).removeClass("checked");

$('#You_id_checkbox').removeAttr("checked");
like image 38
agraterol Avatar answered Oct 06 '22 00:10

agraterol