lundi 23 juillet 2018

Material design checkbox check property is not defined

I have a checkbox that if checked, will check the other checkbox. I am using material design. The check property of the material box checkbox in undefined. How do I make the check property become defined? What am I doing wrong?

This is the link where the problem happens: enter link description here

Thanks, Marcos Camargo

<script>
$(document).ready(function(){
  $("#exclude_all").change(function(){
    console.log('Hello there');
    var element_all = document.querySelectorAll('[id="exclude_all"]');
    var elements = document.querySelectorAll('[id^="exclude_dir_"]');
    for(var i=0, n=elements.length; i<n; i++){
      var element = elements[i];
      if($('#exclude_all').is(":checked")) {
        element.MaterialCheckbox.check();
      } else {
        element.MaterialCheckbox.uncheck();
      }
    }
  });
});
</script>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.grey-light_blue.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

</head>
<body>
<ol style="padding-left:37px;list-style:none;font-size:12px;">
    <li>
        <label id="label_exclude_all" name="label_exclude_all" class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="exclude_all" style="margin-left:3px;padding-left:31px;">
        <input type="checkbox" name="exclude_all" id="exclude_all" class="mdl-checkbox__input" value="Buscar""">
        <span class="mdl-checkbox__label" style="font-size:12px;color:#757575;">Excluir tudo</span>
        </label>
    </li>

    <li>
        <label name="label_exclude_dir_0" id="label_exclude_dir_0" class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="exclude_dir_0" style="margin-left:3px;padding-left:31px;">
        <input type="checkbox" name="exclude_dir_0" id="exclude_dir_0" class="mdl-checkbox__input" value="Atibaia">
        <span class="mdl-checkbox__label" style="font-size:12px;color:#757575;">Atibaia</span>
        </label>
    </li>
</ol>
</body>
</html>



Aucun commentaire:

Enregistrer un commentaire