mdl switch on/off

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/material-design-lite/1.1.3/material.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-lite/1.1.3/material.min.css">
<label id="check" class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-1">
    <input type="checkbox" id="switch-1" class="mdl-switch__input"/>
    <span class="mdl-switch__label">Subscribed</span>
</label>
<input type="button" value="test switch" id="btn"/>

JavaScript

$(function(){
  //set status to true on load
  $('#check')[0].MaterialSwitch.on();
  
  //toggle label
  $('#check input').change(function(){
  	if($(this).is(':checked'))
  		$(this).next().text("Unsubscribed");
  	else
    	$(this).next().text("Subscribed");
  });
});

$("#btn").click(function() {
	if($('#check').is('.is-checked')) {
    $('#check')[0].MaterialSwitch.off();
  }
  else {
  	$('#check')[0].MaterialSwitch.on();
  }
});