0

I am trying to add a sound clip to the span variable created in javascript. But the sound clip is not playing.

Can anyone tell what is the mistake in the code below ??(I included the closing tags in my code)

Here is my code ,

var mySpan=document.createElement('span');

mySpan.innerHTML="embed src=\""+soundfile+"\" hidden=\"true"\ autostart=\ "false" \"

document.body.appenChild(mySpan);

Thanks in advance ..

Prasanth
  • 5,230
  • 2
  • 29
  • 61

2 Answers2

1

appenChild should be appendChild. You're missing a 'd'.

Also, I'm not entirely sure about the syntax around the embed statement. You seem to miss < and >, and your backslashes seem to be positioned oddly.

try:

var mySpan = document.createElement('span');

mySpan.innerHTML = '<embed src="' + soundfile + '" hidden="true" autostart="false">';

document.body.appendChild(mySpan);

Not sure if this is the right way. Just fixing your syntax. :)

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • Thank you !! I need to play the sound clip 5 times if i put it in a loop , the sound clip gets overlapped .. What should i do ? – user2516048 Jun 27 '13 at 10:24
  • You can specify the attributes `loop="5" playcount="5"`. Apparently `playcount` is needed for IE. See: http://www.htmlcodetutorial.com/embeddedobjects/_EMBED_LOOP.html – GolezTrol Jun 27 '13 at 11:11
0
  • Your embed tag does not have opening and closing brackets.

    mySpan.innerHTML='<embed src="'+soundfile+'" hidden="true" autostart='false'></embed>';

  • You mis-spelled appenChild, should have been appendChild

  • Make sure the variable soundfile is initialized to a string with the path to the sound clip.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • I need to play the sound clip 5 times if i put it in a loop , the sound clip gets overlapped .. What should i do ?? – user2516048 Jun 27 '13 at 10:22