Developing Clean AJAX / Javascript Driven Websites; Say No To Tag-Soup

By Angsuman Chakraborty, Gaea News Network
Sunday, November 13, 2005

Behaviour promotes itself as “the missing link for your AJAX apps”. It allows you to use CSS selectors (like id or class) to apply Javascript behaviors to your HTML elements.

No more embedding Javascript tags in your HTML. What Behaviour (note the British spelling) does is allow you to define rules where you associate javascript functions with CSS selectors.

Let’s look at an example (from their site):
Instead of writing:

<li>
	<a onclick="this.parentNode.removeChild(this)" href="#">
		Click me to delete me
	</a>
</li>

With Behaviour we can write:

<ul id="example">
	<li>
		<a href="/anyurl">Click me to delete me</a>
	</li>
</ul>

There is no Javascript embedded in HTML. The actual Javascript function is defined and associated separately.

var myrules = {
	'#example li' : function(el) {
		el.onclick = function() {
			this.parentNode.removeChild(this);

		}
	}
};

Behaviour.register(myrules);

It worked pretty well in my tests. Very much recommended unless you are into code obfuscation. You can download it here.

Discussion
November 22, 2005: 6:59 am

[...] Java IDE For StudentsBehaviour promotes itself as “the missing link for your AJAX apps” and software outsourcing in China hindered by IT talent shortage, whereas, A class action lawsuit against Sony BMG Music Entertainment has been filed in California. [...]

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :