HTML DOM Source type Property
Last Updated :
22 Jun, 2023
The Source type Property in HTML DOM is used to set or return the value of the type attribute in a <source> element. The type attribute is used to specify the MIME type of the media resource.
Syntax:
- It returns the Source type property.
sourceObject.type
- It is used to set the Source type property.
sourceObject.type = MIME_type
Property Values: It contains a single value MIME_type which specifies the MIME_type of the media resource. A few MIME types are video/ogg, videomp4, audio/ogg etc.
Return Value: It returns a string value that represents the MIME_type of the media resource.
Example 1: This example returns the Source type Property.
HTML
<!DOCTYPE html>
< html >
< head >
< style >
body {
text-align: center;
}
h1 {
color: green;
}
</ style >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM Source type property</ h2 >
< audio controls>
< source id = "mySource" src = "gameover.wav" type = "audio/mpeg" >
< source src = "gameover.ogg" type = "audio/ogg" >
</ audio >
< p >
Click the button to get the type of the audio file.
</ p >
< button onclick = "myFunction()" >
Get Source type
</ button >
< p id = "demo" ></ p >
< script >
function myFunction() {
let x =
document.getElementById("mySource").type;
document.getElementById("demo").innerHTML = x;
}
</ script >
</ body >
</ html >
|
Output:
Example 2: This example sets the Source type property.
HTML
<!DOCTYPE html>
< html >
< head >
< style >
body {
text-align: center;
}
h1 {
color: green;
}
</ style >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM Source type property</ h2 >
< audio controls>
< source id = "mySource"
src = "gameover.wav"
type = "audio/mpeg" >
< source src = "gameover.ogg"
type = "audio/ogg" >
</ audio >
< p >
Click the button to set the source
type of the audio file.
</ p >
< button onclick = "myFunction()" >
Set Source type
</ button >
< p id = "demo" ></ p >
< script >
function myFunction() {
let x = document.getElementById("mySource").type = "audio/ogg";
document.getElementById("demo").innerHTML =
"The source type has been changed to " + x;
}
</ script >
</ body >
</ html >
|
Output:
Supported Browsers:
- Google Chrome
- Firefox
- Internet Explorer
- Opera
- Safari
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...