Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can give a class <code>start</code> as well as and <code>data-id</code> to the start buttons.</p> <p>So your html for start button would be like,</p> <pre><code>&lt;img src="start-button.jpg" class="start" data-id="riff1"&gt; //So this is start button for audio elementwith id riff1. </code></pre> <p>How will this work?</p> <pre><code>$('.start').click(function(){ $("#"+$(this).data('id')).play(); //This should do. } </code></pre> <p>And yes in your php file should be type of this,</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Audio Testing&lt;/title&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;?php $randC = rand(2,4); $C = $randC * 4; $G = $C / 2; &lt;script type="text/javascript"&gt; $(document).ready(function() { // $("#start").click(function() // { var time = 0; var riff_time = 2920; var base = 'riff'; &lt;?php for(i = 0; i &lt; $C; i++) { echo " var id = base + ((i + 1) ); window.setTimeout (\"document.getElementById('\" + id + \"').play()\", time); time += riff_time; "; } ?&gt; var timeG = 0; var riff_time = 2920; var baseG = 'riffG'; &lt;?php for(iG = 0; iG &lt; $G; iG++) { echo " var idG = baseG + ((iG + 1) ); window.setTimeout (\"document.getElementById('\" + idG + \"').play()\", timeG); timeG += riff_time; "; // } ?&gt; } }); &lt;/script&gt; &lt;style type="text/css"&gt; &lt;/style&gt; &lt;/head&gt; &lt;body style="background-color: #999;"&gt; &lt;!--&lt;button id="start"&gt;Start&lt;/button&gt; &lt;br&gt; --&gt; &lt;?php echo "C:&lt;br&gt;"; for ($i=1; $i&lt;= $C; $i++) { echo '&lt;audio controls id="riff'.$i.'"&gt; &lt;source src="loopC.ogg" type="audio/ogg"&gt; &lt;/audio&gt;'; } echo "&lt;br&gt;G:&lt;br&gt;"; for ($i=1; $i&lt;= $G; $i++) { echo '&lt;audio controls id="riffG'.$i.'"&gt; &lt;source src="loopG.ogg" type="audio/ogg"&gt; &lt;/audio&gt;'; } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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