How to stop my YouTube iFrame
<p>I made a youtube list where I can click on texts that load youtube videos.</p>

<p>There is only one problem: When I play a video and click on another video link, the video I was playing doesn't stop. So I tried stopping it using jQuery, but no result. </p>

<p>So this is what my php generates: </p>

<pre><code>function generateVideo() {
    echo '&lt;script type="text/javascript" src="scripts/video.js"&gt;&lt;/script&gt;';
    $tags = initTags();
    $query = '
    SELECT * FROM `youtube_links`';
    $result = mysql_query($query);
    if ( !$result) {
        die('Error: '.mysql_error());
    }

    echo '&lt;div id="content"&gt;&lt;table&gt;';
    $i = 0;
    $className = "";
    while ($row = mysql_fetch_array($result)) {
        $i++;
        if ($i == 1) {
            $className = "active";
        } else {
            $className = "inactive";
        }
        echo '
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;a class="'.$className.'" id="item_'.$i.'" onclick="switchVideo(this)"&gt;
                        '.$row['Title'].'
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            ';
    }
    echo '&lt;/table&gt;&lt;/div&gt;';

    $query = '
    SELECT * FROM `youtube_links`';
    $result = mysql_query($query);
    if ( !$result) {
        die('Error: '.mysql_error());
    }

    echo '&lt;div id="videoPlayer"&gt;';

    $i = 0;
    $className = "";
    while ($row = mysql_fetch_array($result)) {
        $link = $row['Link'];
        $i++;
        if ($i == 1) {
            $className = "activePlayer";
        } else {
            $className = "inactivePlayer";
        }
        echo '&lt;iframe class="'.$className.'" id="ytplayer'.$i.'" type="text/html" width="640" height="390"
             src="'.$link.'?version=3&amp;enablejsapi=1"
             frameborder="0"&gt;
             &lt;/iframe&gt;';
    }

    echo '&lt;/div&gt;';
}
</code></pre>

<p>And this is my JavaScript:</p>

<pre><code>function switchVideo(obj) {
    var idText = obj.id;
    var idArray = idText.split("_");
    var id = idArray[1];

    var videoPlayer = document.getElementById('ytplayer' + id);

    var elements = document.getElementsByClassName("activePlayer");

    for (var i = 0; i &lt; elements.length; i++) {
        elements[i].className = "inactivePlayer";
        $(elements[i]).pause();
    }

    $('.inactivePlayer').each(function() {
        $(this).stopVideo();
    }); 


    videoPlayer.className = "activePlayer";
}
</code></pre>

<p>You can see I added the youtube API to the iframes, so what is going wrong?</p>
