Return the MIME type of a media resource:
var x = document.getElementById("mySource").type;
Click the button to return the value of the type attribute of the media resource.
<!DOCTYPE html> <html> <body> <audio controls> <source id="mySource" src="sound.mp3" type="audio/mpeg"> <source src="sound.ogg" type="audio/ogg"> Your browser does not support the audio element. </audio>// ww w . j a v a 2s.co m <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 type property sets or gets the type attribute in a <source> element.
The type attribute sets the MIME type of the media resource.
Property Values
Value | Description |
---|---|
MIME_type | Specifies the MIME type of the media resource. |
Common MIME types:
The type property returns a String representing the MIME type of the media resource.