We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Setting the toggle state of a button


How do I toggle a button programmatically in javascript? I tried the following but it doesn't work

var btn = $("#btn").data("ejToggleButton");
btn.toggleState(false);

1 Reply

BC Berly Christopher Syncfusion Team September 26, 2017 12:35 PM UTC

Hi Louis, 
 
Thanks for contacting Syncfusion support. 
 
We have checked with your query. To make use of ToggleButton’s API please refer the below code example.  
 
Index.cshtml: 
 
<input id="toggle" type="checkbox" />  
<script> 
 
    $("#toggle").ejToggleButton({defaultText:"Play",activeText:"Pause"}); //control initialization 
    var btn = $("#toggle").data("ejToggleButton"); // instance creation for toggle button 
    btn.option("toggleState",false); // toggle state declaration 
</script> 
 
You can define the ToggleState API for the Toggle Button in ASP.NET Core also. Please refer the below code. 
 
Index.cshtml: 
 
<ej-toggle-button id="check11" default-text="play" active-text="pause" toggle-state="false"/> 
 
Please refer the below API Documentation link to know more about toggleState API in the Toggle button. 
 
 
Please refer the below UG documentation link to know more about Toggle button. 
 
We have prepared the simple sample based on your requirement. Please get the sample from the below location. 
 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon