Javascript Reference - HTML DOM Source type Property








The type property sets or gets the value of the type attribute in a <source> element.

Browser Support

type Yes Yes Yes Yes Yes

Syntax

Return the type property.

var v = sourceObject.type

Set the type property.

sourceObject.type=MIME_type

Property Values

Value Description
MIME_type Specifies the MIME type of the media resource.

Common MIME types:
For video:
  • video/ogg
  • video/mp4
  • video/webm
For audio:
  • audio/ogg
  • audio/mpeg




Return Value

A String type value representing the MIME type of the media resource.

Example

The following code shows how to return the MIME type of a media resource.


<!DOCTYPE html>
<html>
<body>
<!--from  w  w  w.  ja v  a 2 s  . c o  m-->
<audio controls>
  <source id="mySource" src="http://java2s.com/style/demo/rain.mp3" type="audio/mpeg">
  <source src="horse.ogg" type="audio/ogg">
</audio>
<p id="demo"></p>

<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    var x = document.getElementById("mySource").type;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: