I need to create audio tag with bunch of attributes.
I have
var audioPlayer=document.createElement('audio');
var audioSource=document.createElement('source');
audioSource.type="audio/mp3";
audioPlayer.controls="controls";
audioPlayer.autoplay="autoplay";
$('div').append(audioPlayer);
My html become:
in Chrome
<audio controls autoplay id='test', class='classname'>
</audio>
in FF
<audio controls='' autoplay='' id='test', class='classname'>
</audio>
What should i do to create these in javascript? Thanks a lot!
controlsandautoplayare boolean values, meaning just the presence of the attribute is enough – its value makes no difference.Personally I like to set
audioPlayer.controls = true;since it’s boolean.