title: How do I use Javascript to toggle play/pause for multiple videos when I click on the video?
body: <p>When I add <code>onclick=&quot;playPause()&quot;</code> to just one video it works great. I click the video and it'll play or pause just like I want it to. If I have more than one video, even if the videos have different IDs (for example: <code>video id=&quot;v1&quot;</code> and <code>video id=&quot;v2&quot;</code>) whenever I click on one video it'll always play one specific video. Using this script on multiple videos seems to only allow play/pause toggling on one video. Here's the html and script I'm using:</p>
  <pre><code>&lt;video id=&quot;v1&quot; width=&quot;480px&quot; height=&quot;267px&quot; controls onclick=&quot;playPause()&quot;&gt;
  &lt;source src=&quot;S12E13%203%20Acts%20of%20God.mp4&quot; type=&quot;video/mp4&quot;&gt;
  &lt;/video&gt;
      &lt;script&gt; 
  var myVideo = document.getElementById(&quot;v1&quot;); 
  function playPause() { 
  if (myVideo.paused) 
      myVideo.play(); 
  else 
      myVideo.pause(); } 
      &lt;/script&gt;
  
  
  &lt;video id=&quot;v2&quot; width=&quot;480px&quot; height=&quot;267px&quot; controls onclick=&quot;playPause()&quot;&gt;
  &lt;source src=&quot;S12E13%203%20Acts%20of%20God.mp4&quot; type=&quot;video/mp4&quot;&gt;
  &lt;/video&gt;
      &lt;script&gt; 
  var myVideo = document.getElementById(&quot;v2&quot;); 
  function playPause() { 
  if (myVideo.paused) 
      myVideo.play(); 
  else 
      myVideo.pause(); } 
      &lt;/script&gt;
  
  
  &lt;video id=&quot;v3&quot; width=&quot;480px&quot; height=&quot;267px&quot; controls onclick=&quot;playPause()&quot;&gt;
  &lt;source src=&quot;S12E13%203%20Acts%20of%20God.mp4&quot; type=&quot;video/mp4&quot;&gt;
  &lt;/video&gt;
      &lt;script&gt; 
  var myVideo = document.getElementById(&quot;v3&quot;); 
  function playPause() { 
  if (myVideo.paused) 
      myVideo.play(); 
  else 
      myVideo.pause(); } 
      &lt;/script&gt;
  </code></pre>
  <p>BTW: not a big deal, but I've noticed the original Play button doesn't work anymore when I use this script. Is there a way to fix that?</p>