Open Directory Site XML Tutorials

ASP | XML | VBScript | JavaScript | ADO | CSS | XMLDOM | PHP | Operating Systems

Home >> XML >>XML Behaviors - the new DHTML?

XML Behaviors - the new DHTML?

 

A behavior is a CSS attribute selector. It can point to an XML file that contains code to be executed against elements in a Web page.

Behaviors is not a W3C standard, but a Microsoft only technology.

Behaviors - What are they?

A behavior is a new CSS attribute selector.

A behavior selector can point to a separate XML file that contains code to be executed against XML or HTML elements in a Web page.

Did you understand that? A method for completely removing script code from HTML pages? That's great! Now we can start writing script libraries, and attach our scripts to any element we want!

How does it work?

Take a look at this HTML file. It has a <style> element that defines a behavior for the <h1> element:

<html>

<head>

<style>

h1 { behavior: url(behave.htc) }

</style>

</head>

<body>

<h1>Move your Mouse over me</h1>

</body>

</html>

The behavior code is stored in an XML document behave.htc as shown below:

<component>

<attach for="element" event="onmouseover" handler="hig_lite" /> <attach for="element" event="onmouseout" handler="low_lite" /> <script language="JavaScript">

function hig_lite()

{

element.style.color=255

}

function low_lite()

{

element.style.color=0

}

</script>

</component>

The behavior file contains JavaScript. The script is wrapped in a <component> element. The component wrapper also contains the event handlers for the script. Nice behavior, isn't it?

Cheap Web Hosting Articles - Web Site Design & Web Hosting Tutorials - Domain Hosting