Reputation: 704
I'm setting up a website, and want to create an HTML5 audio player, but inject the source later on with JavaScript. I have prepared the following HTML:
<audio id=show>
<source id=oggFile type=audio/ogg />
<source id=mp3File type=audio/mpeg />
</audio>
Unfortunately, the W3C validator is panning my code, claiming src
is a required attribute. Due to the way collateral code interacts with the player, I would strongly prefer not having this set to a valid audio file. I have for testing set the src
to a dummy file...
<audio id=show>
<source id=oggFile src=/audio/does-not-exist.ogg type=audio/ogg />
<source id=mp3File src=/audio/does-not-exist.mp3 type=audio/mpeg />
</audio>
...but I'm not sure this is the best approach, and, in Firefox at least, it throws up warnings in the console.
Is there a way I can set an effectively-blank src
attribute that still validates?
Upvotes: 3
Views: 3612
Reputation: 157048
I would suggest to create the source when needed. You can simply do that using JavaScript. In this way, your code is still valid.
Had to look for it but got it now. Here is an answer that will help you with the code.
Upvotes: 2