JSFiddle - React, Tailwind, and code Playground
HTML
<button id="toggle">Start/Stop</button>
JavaScript
(function($) {
var toggle;
var audioContext = new webkitAudioContext();
var osc = null;
$(function() {
toggle = $('#toggle');
toggle.on('click', function() {
if(osc == null) {
osc = audioContext.createOscillator();
osc.frequency.value = 500;
osc.connect( audioContext.destination );
osc.start( audioContext.currentTime );
} else {
osc.stop( audioContext.currentTime );
osc = null;
}
});
});
}(jQuery));