$(‘audio#pop’) uses jQuery to select all audio elements with an id of ‘pop’. This will return an array, so you need to specify the first element by adding [0] . Finally, . play() will play your soundbite.
How to play and pause audio using jQuery?
$(‘.play’). click(function(){ var $this = $(this); var id = $this. attr(‘id’). replace(/btn/, ”); $this. toggleClass(‘active’); if($this. hasClass(‘active’)){ $this. text(‘pause’); $(‘audio[id^=”sound”]’)[id-1]. play(); } else {
How to create audio player in JavaScript?
Step 1: HTML and CSS. First, we’ll create the HTML and CSS for our Audio player. We’ll use a basic layout with a header, a main section, and a footer. Step 2: JavaScript. First, we’ll create an array of Audio with their information, like title, artist, and file path.
How to add jPlayer to HTML?
To use jPlayer, add the following line to the HTML of your
: