Setar option when marking / unchecking checkbox

0

I need to reset a select through checkbox . The problem is when I try to access option with jQuery.

HTML

<select id="selSub">
 <option value="0" >Selecione</option>
 <option value="1" >1</option>
 <option value="2" >2</option>
</select>

jQuery

$(document).ready(function(){
  var checkBox = $("#c1").prop('checked');
  $('#divSubIn').hide();
  $("#c1").click(function(){
    if($('#c1').is(":checked")) {
      //IF CHECKED      
      $('#label1').text("insira uma nova >>");
      $('#divSubSel').hide();
      $('#divSubIn').show();
      $('#selSub').material_select('selectedIndex', 0);
    }else{
      //IF UNCHECKED
      $('#label1').text("Inserir subcategoria nova");
      $('#divSubSel').show();
      $('#divSubIn').hide();      
    }
  });  
});

Within the // IF CHECKED the fourth element $('#selSub').material_select('selectedIndex', 0); should return the select to normal = <option value="0" >Selecione</option> .

    
asked by anonymous 22.03.2017 / 22:25

1 answer

0

Just do it like this

$('#selSub').val('0');

Sources:

link

link

    
23.03.2017 / 17:49