It's not very similar to jQuery, anyway, you can do it with .attr() what is it? :
$('img').attr('src', function(index, src) { return 'http://cdn.something.com' + src; });
This will affect all your <img> nodes in your markup and replace src .
In any case, I'm not sure if this is a great idea. During the DOMready event, the browser may have already tried to access the source attribute old . If you need to do this in Javascript, it might be better to store the path info in the user data attribute so that the browser does not want to load the image. It might look like this:
HTML
<img src='' data-path='/img/picture1.jpg' />
Js
$(function() { $('img').attr('src', function(index, src) { return 'http://cdn.something.com' + this.getAttribute('data-path'); }); });
That should do it. You can replace this.getAttribute() with $(this).data('path') since jQuery parses these data attributes into "node" hash data. But this would create another jQuery object that is not needed at the moment.
jAndy source share