Nate's Programming Blog

Behaviour is a new javascript library that I’ve been using lately. It really compliments unobtrusive javascript. It allows you to define rules that map css style selectors to javascript functions. Here is an example of using a hyperlink class to define a common functionality for all links on a page that contain that class.

window.onload = function () {

function defineRules() {
return {
‘a.popup’ : function (element) {
var popupLocation = element.href;
element.onclick = function () {;
element.href = ‘javascript:void(0);’;

This will look at the page and every hyperlink with the class popup with be converted to a javascript popup using the href value. It is really nice because degrades nicely when javascript is disabled.

Name (required)

Email (required)


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Feel free to leave a comment