This is because the resulting concatenated string for such a URL is ill-formed
url('http://www.marsnjak.com/sergej/yemen/highres/402%20-%20Old%20San'a'.jpg')
Notice how the URL string is truncated to
http://www.marsnjak.com/sergej/yemen/highres/402%20-%20Old%20San.
The fix is trivial: changing the aforementioned statement to
img.style.backgroundImage = 'url("'+img.src+'")';
should generate the intended string
url("http://www.marsnjak.com/sergej/yemen/highres/402%20-%20Old%20San'a'.jpg")
Due to the way the background image is created
img.style.backgroundImage = "url('"+img.src+"')";
links with one or more single quotation marks (a valid non-encoded URI character) such as http://www.marsnjak.com/sergej/yemen/highres/402%20-%20Old%20San'a'.jpg will fail to show.
This is because the resulting concatenated string for such a URL is ill-formed
url('http://www.marsnjak.com/sergej/yemen/highres/402%20-%20Old%20San'a'.jpg')
Notice how the URL string is truncated to
http://www.marsnjak.com/sergej/yemen/highres/402%20-%20Old%20San
.The fix is trivial: changing the aforementioned statement to
img.style.backgroundImage = 'url("'+img.src+'")';
should generate the intended string
url("http://www.marsnjak.com/sergej/yemen/highres/402%20-%20Old%20San'a'.jpg")