You are here: Reference > JavaScript > client-side > HTML DOM > properties > volume (bgsound)

volume property (bgsound)

Browser support:
Specifies or returns the volume for the background sound.

Syntax:

object.volume;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: volume

Possible values:

Integer that sets or retrieves the volume of the media, in the range from -10000 to 0. Zero is the maximum output volume.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the volume attribute:
<bgsound id="myBgSound" src="budgie.wav" loop="-1" volume="-2000">
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the volume property:
<head>
    <script type="text/javascript">
        function ChangeVolume (elem) {
            var bgSound = document.getElementById ("myBgSound");
            
            // Returns the index of the selected option
            var whichSelected = elem.selectedIndex;

            // Returns the text of the selected option
            var soundVolume = elem.options[whichSelected].text;

            if ('volume' in bgSound) {
                bgSound.volume = soundVolume;
            } else {
                alert ("Your browser doesn't support this example!");
            }
        }
    </script>
</head>
<body>
    <bgsound id="myBgSound" src="budgie.wav" loop="-1" volume="-2000">

    <select onchange="ChangeVolume (this);" size="5">
        <option />-10000
        <option />-8000
        <option />-4000
        <option selected="selected" />-2000
        <option />0
    </select>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content