javascript - How to hide table row has unchecked input using jquery -


i'm trying filter when button pressed show row has checked input in table.

<table class="table">     <tr>         <th>name</th>         <th>inuse</th>         <th></th>     </tr>     <tr>         <td>foo 1</td>         <td>             <input checked="checked" class="check-box" disabled="disabled" type="checkbox" />         </td>         <td>             <a href="/additivesnames/edit/5">edit</a> |             <a href="/additivesnames/details/5">details</a> |             <a href="/additivesnames/delete/5">delete</a>         </td>     </tr>     <tr>         <td>foo 2</td>         <td>             <input checked="checked" class="check-box" disabled="disabled" type="checkbox" />         </td>         <td>             <a href="/additivesnames/edit/3">edit</a> |             <a href="/additivesnames/details/3">details</a> |             <a href="/additivesnames/delete/3">delete</a>         </td>     <tr/>     <!-- not checked -->     <tr>         <td>foo 3</td>         <td>             <input class="check-box" disabled="disabled" type="checkbox" />         </td>         <td>             <a href="/additivesnames/edit/5">edit</a> |             <a href="/additivesnames/details/5">details</a> |             <a href="/additivesnames/delete/5">delete</a>         </td>     </tr> </table> 

you can use :has selector or .has() method checking existence of element in parent.

$("button").click(function(){      $("table tr").has(".check-box:not(:checked)").hide();  });
table, tr, td {      border: 1px solid black;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table>      <tr>          <th>name</th>          <th>inuse</th>      </tr>      <tr>          <td>foo 1</td>          <td>              <input class="check-box" type="checkbox" checked disabled  />          </td>      </tr>      <tr>          <td>foo 2</td>                            <td>              <input class="check-box" type="checkbox" disabled  />          </td>      </tr>      <tr>          <td>foo 3</td>                            <td>              <input class="check-box" type="checkbox" checked disabled  />          </td>      </tr>      <tr>          <td>foo 4</td>                            <td>              <input class="check-box" type="checkbox" disabled  />          </td>      </tr>  </table>  <button>only checked</button>

you can test code on full of html in demo


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -