title: change image SRC and Style
body: <p>Hi I want to rewrite an image Src and Style element.
  The image tag has an element called "data-orig-file" wich has the url that I want to write to the src element.
  I came up with this but I'm not good at javascript:</p>
  
  <pre><code>function changeImageSrc(img) {
  var newurl= document.getElementById("img").getAttribute('data-orig-file');
  var oldurl= document.getElementById("img").src;
  document.getElementById("img").src = img.src.replace(oldurl, newurl);
  }
  </code></pre>
  
  <p>Now Secondly I want to grab the "Style" element with it's values from the grandparent div of the image and write that style to the image instead of the original style.</p>
  
  <p>Finally I want to do these two things on all images inside a container div on a page when it is loaded (I suppose).</p>
  
  <p>Any help is greatly apreciated!!</p>
  
  <p>Thanks</p>
  
  <p>update:</p>
  
  <p>what I came up with so far is this:</p>
  
  <pre><code>function ChangeImageSrc() {
  var image=document.getElementById("img");
  var div=document.getElementById("LastPost");;
  
  for each (image in div) {
  var newurl= document.getElementById("img").getAttribute('data-orig-file');
  var oldurl= document.getElementById("img").src;
  document.getElementById("img").src = img.src.replace(oldurl, newurl);
  }
  }
  
  window.onload = function()
              {
                 ChangeImageSrc();
              };
  </code></pre>
  
  <p>I also tried it with an "onload" event on the body element like this (instead of the wondow.onload part):</p>
  
  <pre><code>onload="javascript:ChangeImageSrc()
  </code></pre>
  
  <p>Both don't work this far :(</p>
  
  <p>Ok AffluentOwl, here's the HTML:</p>
  
  <pre><code>&lt;div class="gallery-group images-1" style="width: 677px; height: 507px;"&gt;
  &lt;div class="tiled-gallery-item tiled-gallery-item-large"&gt;
  &lt;a href="http://i0.wp.com/www.mydomain.com/wp-content/uploads/..../../image.jpg" class="zoom"&gt;
  &lt;img data-attachment-id="5786" data-orig-file="http://www.mydomain.com/wp-content/uploads/..../../image.jpg" data-orig-size="1333,1000"  data-medium-file="http://www.mydomain.com/wp-content/uploads/..../../image-300x225.jpg" data-large-file="http://www.mydomain.com/wp-content/uploads/..../../image-1024x768.jpg" src="http://i0.wp.com/www.mydomain.com/wp-content/uploads/..../../image.jpg?resize=1191%2C893" align="left" title="shelter-childrens-farm" data-recalc-dims="1" style="width: 73px; height: 9px;"&gt;
  &lt;/a&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>As you can see there is a CDN prefix to the url that I'm trying to loose (for good reasons, it's opposed to me by wordpress and doesn't work for me).
  The second thing is about the style of the image tag, that's somehow set to the wrong dimensions so I want to grab the right size from the first div (top of code).</p>