I want to create a simple user interaction with a single button to start and stop recording audio,like whatsapp. I've looked on stackoverflow to understand if I was wrong, as I know it's not possible to bind on the same element two click events, so I've decided to test the code on codepen but it will not produce the expected result:
$('#audioBtn').on('click' ,function(e){
e.preventDefault();
if( $(this).hasClass('active') ){
$(this).removeClass('active')
.addClass('inactive');
console.log('Recording stopped');
}
});
$('#audioBtn').on('click' , function(e){
e.preventDefault();
if( $(this).hasClass('inactive') ){
$(this).addClass('active')
.removeClass('inactive');
console.log('Recording start');
}
});
What happening is that the two events are logged on console at the same time, but this is not what I want, I just want to use the same button to start and stop the recordings and change the icon while the user is recording the audio. Is there any way to do this?