1

Can anyone please show me the code for toggle button in ratchet framework. i mean if toggle button is enable {do something} else{do something else}. i didnt got it anywhere in web.

<div  id="myToggle" class="toggle active">
        <div class="toggle-handle"></div>
    </div>  
    <script type="text/javascript" charset="utf-8">
    document.querySelector('#myToggle').addEventListener('toggle', myFunction)
    function myFunction()
    {
        if(document.getElementById("myToggle").className == 'toggle active')
        {
        document.getElementById("demo").innerHTML="ON";
        }
        else
        {
        document.getElementById("demo").innerHTML="OFF";
        }

    };
    </script>

For others who face the problem.The above code worked for me.

Schmalzy
  • 17,044
  • 7
  • 46
  • 47
Chetan Shah
  • 129
  • 14

1 Answers1

0

The myFunction recieves the event object, which contains info about the toggle state. Try something like this:

function myFunction(e) {
    if(e.detail.isActive) {
        document.getElementById("demo").innerHTML="ON";
    } else {
        document.getElementById("demo").innerHTML="OFF";
    }
};
Marek Roj
  • 1,221
  • 8
  • 10