Jump to content

innerHTML


smiles
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...