Firelord
Kids

I can be reached via email at nyven@firelord.net.

Modified Behavior

I wrote a short article for my company on using Ben Nolan's behaviour.js to apply behavior to nodes identified by CSS selectors. I'd been previously using Dean Edward's CSSQuery classes to query my DOM. As a consequence of these two things, I decided to modify Ben's implementation to use CSSQuery.

You can download "Modified Behavior" here. You will also need Dean Edwards CSSQuery.

ModifiedBehavior v1.0 by Ron Lancaster based on Ben Nolan's Behaviour, June 2005 implementation. Modified to use Dean Edward's CSS Query.

Description

Uses css selectors to apply javascript Behaviors to enable unobtrusive javascript in html documents.

Dependencies

Requires Dean Edwards CSSQuery.

Usage

    Behavior.register(
        "b.someclass",
        function(element) {
            element.onclick = function(){
                alert(this.innerHTML);
            }
        }
    );

    Behavior.register(
        "#someid u",
        function(element) {
            element.onmouseover = function(){
                this.innerHTML = "BLAH!";
            }
        },
        document.getElementByID("parent")
    );

Call Behavior.apply() to re-apply the rules (if you update the dom, etc).

License

Reproduced under BSD licensed. Same license as Ben Nolan's implementation.

More information for Ben Nolan's implementation: http://bennolan.com/behaviour/

Referrers