title: Jquery add title attribute with data from JSON call
body: <p>I'm trying to dynamically add titles to a number of images using values obtained from a JSON call.</p>
  
  <p>This is what I have so far </p>
  
  <pre><code>$(".watch_view img").each(function() {
  $.ajax({
      url: 'http://gdata.youtube.com/feeds/api/videos/T2aMBeeM4yw?v=2&amp;alt=jsonc',
      dataType: 'json',
      success: function(json) {   
      song_title = json.data.title;// song title is retrieved without issue                           
      }   
      });
  
     alert(song_title); //this to be removed
     //the title attr below is only added when the above alert is in place    
     $(this).attr('title', song_title);
     $(this).attr('alt', "This works everytime"); 
     });
  </code></pre>
  
  <p>
  </p>
  
  <p>Now the above works but only when I "stop" the process by adding in the unwanted alert - I can only guess that the code is executing before it has retrieved the data from the JSON call (?) and the alert enables it to catch up.</p>
  
  <p>I imagine I need another function that executes after the JSON call or for the code to go into the 'success' function but I'm not sure how to keep hold of the 'this' element if that is the case.</p>
  
  <p>Help and advice greatly appreciated.</p>
  
  <p>Thanks</p>
  
  <p>Chris</p>