<p>I'm inserting an img tag into my document with the new Element constructor like this (this works just fine):</p>

<pre><code>$('placeholder').insert(new Element("img", {id:'something', src:myImage}))
</code></pre>

<p>I would like to trigger a function when this image loads, but I can't figure out the correct syntax. I'm guess it's something like this (which doesn't work).</p>

<pre><code>$('placeholder').insert(new Element("img", 
    {id:'something', src:myImage, onload:function(){alert("MOO")}}))
</code></pre>

<p>I'm hoping to do this in the same line of code and not to have to attach an event observer separately.</p>

<p><strong>EDIT:</strong> The event needs to be registered when the element is <strong>created</strong>, not after. If the image loads before the event is attached, the event will never fire.</p>

You might have to move the function elsewhere and call it by name
```
```
$('placeholder').insert(new Element("img", 
    {id:'something', src:myImage, onload:"javascript:moo()"}))

function moo() {
    alert("MOO");
}
```
```
Of course, because
```
insert
```
returns the element, you could inline
```
Element.observe
```
```
```
$('placeholder').insert(new Element("img", 
    {id:'something', src:myImage})).observe('load', function(){alert("MOO")});
```
```