javascript - jquery disable checkbox by default -


my current script toggling between disabled , enabled.

<script>     $("#filter").attr('checked', !$("#mylist")[0].disabled);     $("#filter").click(function() {         $("#mylist").attr('disabled', !this.checked)     }); </script> 

and html code is:

<div>     <div class="checkbox">         <input type="checkbox" checked="checked" id="filter" />         <label for="filter">types</label>         <br>     </div>     <select class="selectpicker" id="mylist" multiple>         <option>a</option>         <option>b</option>         <option>c</option>     </select> </div> 

by default checkbox checked, , when remove `checked="checked" , doesn't work @ all.
how can disable default , enable/disable afterwards?

are need .if uncheck = disable ,check=enable.in default case unchecked disable.change default checked enable

$(document).ready(function (){      $("#filter").attr('checked', false);      if(!$("#filter").attr('checked')){          $("#mylist").attr('disabled',"true");      }      $("#filter").click(function() {          $("#mylist").attr('disabled', !this.checked);      });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div>    <div class="checkbox">      <input type="checkbox"  id="filter" />      <label for="filter">types</label>      <br>    </div>    <select class="selectpicker" id="mylist" multiple>      <option>a</option>      <option>b</option>      <option>c</option>    </select>  </div>


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -