Hmm… probably because if you view the source, the scripts are being placed at the very bottom of the body (which is how your suppose to do it). So what you need to do is try moving that code into your head and running it. Since it is such a tiny bit of code you could probably defer it so the code completes before it ever moves into the img element.
EDIT: Hmm… hang on.. i see exactly what you are talking about.
Is there any dynamic reason to be replacing the images? Trying to manipulate an element like that is very tricky (if it can even be really done). What are you trying to accomplish, there may be a better alternative.