Source type Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Source


The type property sets or gets the value of the type attribute in a <source> element, which sets the MIME type of the media resource.

Set the type property with the following Values

Value Description
MIME_type Sets 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, representing the MIME type of the media resource

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<audio controls>
  <source id="mySource" src="your.mp3" type="audio/mpeg">
  <source src="your.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>/* ww w  .j a va  2s. com*/

<p id="demo"></p>

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

function myFunction() {
    var x = document.getElementById("mySource").type;
    document.getElementById("demo").innerHTML = x;


Related Tutorials