Jump to content

innerHTML


smiles

Recommended Posts

<div id="music"><embedsrc="beatles.mid"width="50%"height="50%"></embed></div><script type="text/javascript">document.getElementById('music').innerHTML="<embedsrc='beatles.mid'width='5%'height='5%'></embed>"</script>

Just try to test before making a pulldown list of songs (when you choose one in pull down list, you will have another)But the tested code above doesn't work, width and height still the same as before ?Anyone know why ???

Link to comment
Share on other sites

Just try to test before making a pulldown list of songs (when you choose one in pull down list, you will have another)But the tested code above doesn't work, width and height still the same as before ?Anyone know why ???
Try putting the code all on one line.It doesn't read the part in quotes like the way you want.If you really need (or want) the stuff on separate lines, then use something like
<div id="music"><embedsrc="beatles.mid"width="50%"height="50%"></embed></div><script type="text/javascript">newHtml="<embed";newHtml+="\nsrc='beatles.mid'";newHtml+="\nwidth='5%'";newHtml+="\nheight='5%'>";newHtml+="\n</embed>";document.getElementById('music').innerHTML=newHtml;</script>

Other than having the javascript stuff on multiple lines, the code's okay, I think.It might not produce the code as it is in your post, on separate lines. Adding line breaks on each line doesn't seem to work when I view the source code... but I'm not sure if you need to have it all on different lines. It shows up properly using the "alert" (which is how I debug my code), but I think Firefox tends to do stuff to HTML to fix stuff, so it might change the code. (e.g. it removes the closing EMBED tag, since it's not needed)Also, the EMBED element doesn't need a closing tag... you can just close the opening tag ( <embed ... /> ). And the embed element is being deprecated in favour of the OBJECT element...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...