Javascript Loop and Button
<p>Hello wonderful web programmers. I need some help, and I believe there must be a simple answer.</p>

<p><strong>The Goal</strong>
I need to be able to pause all Vimeo Videos on a WordPress webpage. I would really like it if I could just add a class "pause" to any tag (so I could use a div or anchor rather than just a button) and have that pause all playing videos.</p>

<p>The following code works if I have buttons, but it only works on the first video. Apparently I need to make a loop of some sort to have it work on all of the videos on a page:</p>

<p><strong>The Code</strong></p>

<pre><code>&lt;button class="simple"&gt;play&lt;/button&gt; &lt;button  class="simple"&gt;pause&lt;/button&gt;


&lt;script&gt;
//HERE IS THE SIMPLE CODE THAT WORKS
    var f = $('iframe'),
    url = f.attr('src').split('?')[0];

// postMessage
function post(action, value) {
    var data = { method: action };
    if (value) {
        data.value = value;
    }
    f[0].contentWindow.postMessage(JSON.stringify(data), url);
}
// Play &amp; Pause 
$('button').click(function() {
    post($(this).text());
});


if (window.addEventListener){
    window.addEventListener('message', onMessageReceived, false);
} else { // IE
    window.attachEvent('onmessage', onMessageReceived, false);
}
&lt;/script&gt;
</code></pre>

<p><strong>The Question</strong>
Where would the loop go? Also, what should I change so that another element can pause? Here is some other code where a class is used:</p>

<pre><code>/**
                     * Sets up the actions for the buttons that will perform simple
                     * api calls to Froogaloop (play, pause, etc.). These api methods
                     * are actions performed on the player that take no parameters and
                     * return no values.
                     */
                    function setupSimpleButtons() {

                        var buttons = container.querySelector('div .simple'),
                            playBtn = buttons.querySelector('.play'),
                            pauseBtn = buttons.querySelector('.pause'),
                            unloadBtn = buttons.querySelector('.unload');

                        // Call play when play button clicked
                        addEvent(playBtn, 'click', function() {
                            froogaloop.api('play');
                        }, false);

                        // Call pause when pause button clicked
                        addEvent(pauseBtn, 'click', function() {
                            froogaloop.api('pause');
                        }, false);

                        // Call unload when unload button clicked
                        addEvent(unloadBtn, 'click', function() {
                            froogaloop.api('unload');
                        }, false);
                    }



                    setupSimpleButtons();
                    setupEventListeners();
</code></pre>
