Reputation: 1083
I want to pause all audio elements on my page and reset the currentTime to 0.
When I loop through the jquery elements I'm getting error a.pause is not a function
and Cannot create property 'currentTime' on number '0'
var audio = $('audio')
audio.each((a) => {
a.pause()
a.currentTime = 0
})
Upvotes: 0
Views: 331
Reputation: 1091
Please take a look at the official documentation of .each
.
To summarize, the first argument of .each
is the index of the audio element and the second one is the audio element itself, so the solution would be:
var audios = $('audio')
audios.each((i, a) => {
a.pause()
a.currentTime = 0
});
Upvotes: 3