title: How to sort table by checkbox checked attribute
body: <p>I'm new to javascript, and I've got a problem I can't solve for some time...
  I need to sort table on the fly. The (borrowed) code is:</p>
  
  <pre><code>function sortTable(n) {
        var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
        table = document.getElementById("myTable2");
        switching = true;
        dir = "asc"; 
  
        while (switching) {
  
          switching = false;
          rows = table.getElementsByTagName("TR");
          for (i = 1; i &lt; (rows.length - 1); i++) {
            shouldSwitch = false;
            x = rows[i].getElementsByTagName("TD")[n];
            y = rows[i + 1].getElementsByTagName("TD")[n];
  
            if (dir == "asc") {
              if (x.innerHTML.toLowerCase() &gt; y.innerHTML.toLowerCase()) {
                shouldSwitch= true;
                break;
              }
            } else if (dir == "desc") {
              if (x.innerHTML.toLowerCase() &lt; y.innerHTML.toLowerCase()) {
                shouldSwitch= true;
                break;
              }
            }
          }
          if (shouldSwitch) {
            rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
            switching = true;
            switchcount ++; 
          } else {
            if (switchcount == 0 &amp;&amp; dir == "asc") {
              dir = "desc";
              switching = true;
            }
          }
        }
      }
  </code></pre>
  
  <p>It works fine with text/numeral values, but the problem is that one of the columns in the table consists of checkboxes. And idea is to sort the table the way rows with checked checkboxes are on top (/bottom, depending on ascending/descending direction).</p>
  
  <p>I tried to check for <code>x.innerHTML.checked==true</code>, but <code>x.innerHTML.checked</code> returns "undefined" so there's no use from this.</p>
  
  <p>Any advice please?</p>