Checkboxer for single selection

jQuery for change checkboxes to single selection mode

by Pedro Borrego

HTML

<table class="table">
  <tbody>

    <tr>
      <td>
        <input id="CheckBox1" type="checkbox" checked="checked">
      </td>
      <td>
        <span id="mylabel">option one</span>
      </td>
    </tr>
    <tr>
      <td>
        <input id="CheckBox1" type="checkbox">
      </td>
      <td class="text-left">
        <span id="mylabel">option two</span>
      </td>
    </tr>
    <tr>
      <td>
        <input id="CheckBox1" type="checkbox">
      </td>
      <td>
        <span id="mylabel">option two</span>
      </td>
    </tr>
    <tr>
      <td>
        <input id="CheckBox1" type="checkbox">
      </td>
      <td>
        <span id="mylabel">option two</span>
      </td>
    </tr>
  </tbody>
</table>

JavaScript

$(document).ready(function() {
   var $radiocheck = $(":checkbox");
   $radiocheck.on('click', function() {
     $radiocheck.not(this).attr('checked', false);
     this.checked = this.checked === true ? true : false;
   });
 });