The src
property sets or gets the value of the src attribute in a <source> element.
src |
Yes | Yes | Yes | Yes | Yes |
Return the src property.
var v = sourceObject.src
Set the src property.
sourceObject.src=URL
Value | Description |
---|---|
URL | Specifies the URL of the media file. |
Possible values.
A String type value representing the URL of the media file.
The following code shows how to get the URL of a media file.
<!DOCTYPE html>
<html>
<body>
<!-- w w w. ja va 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").src;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: