2007-05-18

Event.observe() and onclick

Make a dynamic link to use it as a control on your application. Sure, it’s simple. But sometimes you forgot the correct order of definitions:

<script type="text/javascript">

// create a <a>-Object

var link = Builder.node('a', {href:document.location.href}, 'do foo');

// define the Eventhandler

Event.observe(link, 'click', this.onRemove.bindAsEventListener(this));

// define the onclick-attribute

link.setAttribute('onclick','return false');

</script>

So, why I do talk about this little exercise? Because, if you change the order of definition the Element-Attribute and Event-Handler, the Event-Handler overwrites the attribut-action.

(seen on Firefox 2.0.0.3)

Home Writing Rides Travel Photos Journal