You are here: Reference > JavaScript > client-side > HTML DOM > properties > loop (bgsound, img, input:image)

loop property (bgsound, img, input:image)

Browser support:
Specifies or returns the number of repeats for a sound or video clip.

Syntax:

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

Possible values:

The 'infinite' string constant or an integer that sets or retrieves the number of repeats.
One of the following values:
infinite
Repeats infinitely.
-1
Repeats infinitely.
0
Repeats only once.
repeatCount
Positive integer, the number of repeats.
Default: 1.

Example HTML code 1:

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

Example HTML code 2:

This example illustrates the use of the loop property:
<head>
    <script type="text/javascript">
        function ChangeLoop () {
            var bgSound = document.getElementById ("myBgSound");

            if ('loop' in bgSound) {
                bgSound.loop = 3;
            } else {
                alert ("Your browser doesn't support this example!");
            }
        }
    </script>
</head>
<body>
    <bgsound id="myBgSound" src="budgie.wav" loop="0">
    <button onclick="ChangeLoop ();">Repeat it 3 times!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content