Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How Can I call 2 different function using one toggle button in vanilla javascript

I am Using annyang.js for speech-recognition which have 2 different functions, for start annyang.start() and for stop annyang.abort()
Now how do i make a toggle button which will fire both of these functions?

my code

<div class="action" onclick="actionToogle()">

JS

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<script>
    function actionToogle() {
      var action = document.querySelector(".action");
      action.classList.toggle("active",annyang.start());
    }
  </script>

currently its just starting the recognition by annyang.start() ,
but i want whenever i click the button the recognition will be stop by annyang.abort()

>Solution :

You can check if action has active class you can start or if it doesnt have you can stop.

function actionToogle() {
  var action = document.querySelector(".action");
  action.classList.toggle("active", );
  
  if (action.classList.contains("active")) {
    // annyang.start();
    console.log("Started");
  } else {
    // annyang.abort();
    console.log("Stop");
  }

}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading