This is my html:
(note: I didn't use a background image on the a just for simplicity to show someone how this could work)
<div class="foo">
<ul>
<li><a href="#" class="bar"><img src="bar.gif" /></a></li>
<li><a href="#" class="baz"><img src="baz.gif" /></a></li>
</ul>
</div>
And my JavaScript:
<script type="text/javascript">
Event.observe(window, 'load', function() {
$$('.foo a').each(function(a) {
alert(a); // this is the anchor
a.observe('click', fooClick);
});
function fooClick(event) {
alert(event.element()); // this is the img
}
</script>
Why is the element in fooClick the image and not the anchor? How should I have done this to use the image.