title: javascript jquery: Overwriting variables - how? better performance?
body: <p>Hey guys,
  i'm not much of a hardcore coder and so I don't get this basics here.</p>
  
  <p>Imagine I have multiple 's on my page (that contain Youtube Videos via swfobject).
  All those object's have a unique ID like ytplayer_12, ytplayer_2, ytplayer_56, etc.</p>
  
  <p>I need to run through all of this ytplayer_'s with jquery and add an EventListener to them.</p>
  
  <p>It works just fine! I just wonder if I'm declaring the variables ($ytid, ytid) in the right place - outside of the <code>onYouTubePlayerReady()</code> function? Or should I declare the vars inside of the function? Or even inside of the each-loop?</p>
  
  <pre><code>var $ytid = '',
      ytid = '';
  
  function onYouTubePlayerReady() {
  
      $('object[id^="ytplayer_"]').each(function() {
  
          $ytid = $(this).attr('id');
          ytid = document.getElementById($ytid);
  
          ytid.addEventListener("onStateChange", "foo");
  
      });
  };
  </code></pre>
  
  <p>I'm just curious what is better in this case and if I'm doing that correct right now?
  Thank you for your info and help?</p>