Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var pos = 0 var sId = 'sound'; function change() { if(pos == 0) { pos = 1; document.getElementById('btn').src="http://www.buzzingup.com/wp-content/uploads/2011/07/stop.png"; var e = document.createElement('embed'); e.setAttribute('src','beep.mp3'); e.setAttribute('id',sId); e.setAttribute('hidden','true'); e.setAttribute('autostart','true'); e.setAttribute('loop','true'); document.body.appendChild(e); } else { pos = 0; document.getElementById('btn').src="http://geekoffices.com/wp-content/uploads/2011/07/start-button-300x299.png"; document.body.removeChild(document.getElementById(sId)); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;img src="http://geekoffices.com/wp-content/uploads/2011/07/start-button-300x299.png" onClick="change()" id="btn" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>How about that, I think it should work.</p> <p><strong>Edit:</strong> Here is an OO version that should do what you need:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function imageSwitch(_imgID,_imgStart,_imgStop,_soundFile) { this.imgID = _imgID; this.imgStart = _imgStart; this.imgStop = _imgStop; this.soundFile = _soundFile; this.pos = 0; this.e; this.change = function() { if(this.pos == 0) { this.pos = 1; document.getElementById(this.imgID).src = this.imgStop; this.e = document.createElement('embed'); this.e.setAttribute('src',this.soundFile); this.e.setAttribute('id','sound'+this.imgID); this.e.setAttribute('hidden','true'); this.e.setAttribute('autostart','true'); this.e.setAttribute('loop','true'); document.body.appendChild(this.e); } else { this.pos = 0; document.getElementById(this.imgID).src = this.imgStart; this.e.parentNode.removeChild(this.e); } } } &lt;/script&gt; &lt;script type="text/javascript"&gt; var abc = new imageSwitch('btn1','http://geekoffices.com/wp-content/uploads/2011/07/start-button-300x299.png','http://www.buzzingup.com/wp-content/uploads/2011/07/stop.png','beep.mp3'); var def = new imageSwitch('btn2','http://geekoffices.com/wp-content/uploads/2011/07/start-button-300x299.png','http://www.buzzingup.com/wp-content/uploads/2011/07/stop.png','beep.mp3'); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;img src="http://geekoffices.com/wp-content/uploads/2011/07/start-button-300x299.png" onClick="abc.change()" id="btn1" /&gt; &lt;img src="http://geekoffices.com/wp-content/uploads/2011/07/start-button-300x299.png" onClick="def.change()" id="btn2" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload