Using jquery:
$("*[src]").attr("src", "http://example.com/somerandomimage.jpg?foo=bar");
In case you intend to replace certain urls only, constrain the selector:
$("*[src='http://example.com/somerandomimage.jpg']").attr("src", "http://example.com/somerandomimage.jpg?foo=bar");
The same operation when having a html string in the first place:
$("*[src='http://example.com/somerandomimage.jpg']", $(<html snippet>)).attr("src", "http://example.com/somerandomimage.jpg?foo=bar");
The <html snippet>
should be well-formed and rooted in a single element.
Force a single root as follows:
$("*[src='http://example.com/somerandomimage.jpg']", $(<html snippet>).wrapAll("<div/>").first().parent()).attr("src", "http://example.com/somerandomimage.jpg?foo=bar");
Note the traversal to the generated root as wrapAll
returns the original jquery object.