title: change all image sources jquery
body: <p>I want to change all image sources if they fail to load. Some companies block access to dropbox so I like to use an alternative link for images. Also, I don't want to modify images and css files. My code does work for the first image but makes every image source the same. How can I fix it? Thanks in advance:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="jquery.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;img  src="img/a.png" alt="img1"/&gt;
   &lt;img  src="img/b.png" alt="img2"/&gt;
  
  &lt;/body&gt;
  
  &lt;script&gt;
  
  var image = new Image();
  image.src = "http://dropbox.com/favicon.ico";
  if (image.height &lt; 0) {
  
  var imgsrc = $('img').attr('src');
  
  var imgsrc1 = imgsrc.substr(imgsrc.lastIndexOf("img/"));
  imgsrc1 = imgsrc.substr(4);
  var imgalt = imgsrc1.substr(4,imgsrc.length - 4);
  
  var imgsrc2 ='t/' + imgsrc1;
  $('img').attr('src',imgsrc2);
  $('img').attr('alt',imgalt);    
  
      } else {
  
  
  var imgsrc = $('img').attr('src');
  
  var imgsrc1 = imgsrc.substr(imgsrc.lastIndexOf("img/"));
  imgsrc1 = imgsrc.substr(4);
  var imgalt = imgsrc1.substr(4,imgsrc.length - 4);
  
  var imgsrc2 ='http://dl.dropbox.com/u/xxxxxx/img/' + imgsrc1;
  $('img').attr('src',imgsrc2);
  $('img').attr('alt',imgalt);    
  
      }
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>