On this site testsite, I’m making a numbers game for ESL students. It uses a flash and a html5 audio player depending on browser (The plugin for somereason uses flash for firefox, but that’s not really important). There are 16 audio tracks. The flash player divs are #f-ONE, #f-TWO etc, while the html5 are #ONE, #TWO etc.
All the audio players are hidden on page load, and then (using the working code from this fiddle http://jsfiddle.net/andrewwhitaker/9BcUP/) when you click the start button, one number from an array of 16 is selected and assigned to variable ran and then either #f- is added if it’s flash or # is added if html5 and then one of the audio players is supposed to show. ran.show(): but it doesn’t work.
For debugging, I put in some console.log(ran) and it shows that the random element from the array is selected and then the div # is being added, but for someone reason the audio player is not showing.
Can you help me figure out why?
I noticed that your markup is:
Note that the element with
id='f-SIX'is inside the element withid='SIX'. This means that when you hide elements withid="NUM", the element withid='F-NUM'is also hidden. Showing the inner element will not cause it to show up because the parent element is hidden (at least this appears to be the case for Google Chrome)Additionally, you have to think about browsers for which only the elements with
id='f-SIX'are going to show up. This occurs because theaudiotag is not supported in some browsers yet, therefore just theobjecttag will show up.I would change your JavaScript as follows:
Also note the use of
display:blockinstead of.show(). The only reason for this is because I couldn’t get theobjecttag to play nice with.show()(any advice on this appreciated).For anyone reading, please read the entire chat transcript to see how I came about this answer.