html – Setting property volume of HTML5 audio with jQuery not working-ThrowExceptions

Exception or error:

I am trying to set the volume of an audio element with jQuery.

<audio class="audio" autoplay="autoplay" controls="controls" src="All_Right.mp3"></audio>

So i am selecting the audio tag and setting the volume like so:

$('.audio').prop(volume, 0.1);

But i got Uncaught Reference Error: volume is not defined

What is wrong with my code?

How to solve:

In your line:

$('.audio').prop(volume, 0.1);

You are passing volume as a variable not as a string. You do not have a variable named volume, which is why you are receiving the error about it not being defined. Try changing it to:

$('.audio').prop("volume", 0.1);

###

Try with this code:

$('.audio').volume = 0.1;

Leave a Reply

Your email address will not be published. Required fields are marked *