Saturday, November 17, 2012

javascript – Button clicked, sound plays, but the button disappears

Like I said in the title. I want different sounds to play but for some reason the text on the button goes away after the sound plays. Button still works though. I need the button to remain intact.


ALSO is there anyway to not make the page reload when the button is clicked?


Here is my code:


javascript:



function playSound() {
var sounds = new Array(
\"battle.mp3\"
);

$(\"button\").html(\"<embed src=\\\"\"+sounds[Math.floor(Math.random()*(sounds.length+1))]+\"\\\" hidden=\\\"true\\\" autostart=\\\"true\\\" />\");


HTML



<div id=\"element\">
<button onclick=\"javascript:playSound()\">Try it</button>
</div>






Rating: 5 out of 5 based on 3 ratings



The post javascript – Button clicked, sound plays, but the button disappears appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-button-clicked-sound-plays-but-the-button-disappears.html

No comments:

Post a Comment