Forside » Behaviour
Background
“Behaviour” is a very small library aimed at helping you write unobtrusive javascript. It was created by Ben Nolan, to whom I give full credit for releases up to and including 1.1. For now, please see Ben’s Behaviour page for documentation. What is available here is an updated version of Behaviour including fixes and enhancements by me, and some members of the newsgroup.
Please note: this version of Behaviour requires Prototype 1.5.1 or later. Prototype is available from prototypejs.org.
How does it work?
Copied directly from Ben, instead of writing:
<ul id="example"> <li> <a onclick="this.parentNode.removeChild(this)" href="#"> Click me to delete me </a> </li> </ul>
you can write:
<ul id="example"> <li> <a href="/someurl">Click me to delete me</a> </li> </ul>
which works (presumably) without javascript. You can then enhance the user-experience unobtrusively with Behaviour:
var myrules = { '#example li': function(el) { Behaviour.addEventObserver(el, 'click', function() { this.parentNode.removeChild(this); return false; // prevent default action }); } }; Behaviour.register(myrules);