asp.net.ph

Skip Navigation Links

addBehavior Method

DHTML Methods


Attaches a behavior to an element.

Syntax

iID = object.addBehavior ( sUrl ) 
Parameters

sUrl Required. String specifying any one of the following values:

sValue Specifies the location of the behavior, in URL format.
"#default#behaviorName" Specifies one of Microsoft® Internet Explorer's default behaviors, identified by its behaviorName.
"#objID" Specifies a binary implementation of a behavior, where objID is the ID attribute specified in an <OBJECT> tag.


Return Value

Integer. Returns an identifier that can be used to detach the behavior from the element using removeBehavior.

Remarks

This method provides an alternative to attaching a behavior to an element without the use of cascading style sheets ( CSS ). For more information on attaching behaviors to elements through the proposed CSS behavior attribute, refer to the links provided in the See Also section.

Unless the behavior specified in the addBehavior call is one of the default behaviors built into Internet Explorer, the addBehavior call causes Internet Explorer® to download the behavior asynchronously, before the behavior is attached to the element.

Due to the asynchronous nature of the addBehavior method, by the time the function call returns, the behavior's properties, methods, or events may not be immediately available for scripting. Waiting for the onreadyStatechange event to fire and verifying that the readyState property of the element is set to complete ensures that the behavior is completely attached to the element. Consequently, all the behavior's members are available for scripting. Otherwise, attempting to use any of the behavior-defined members before the behavior is attached to the element will result in a scripting error indicating that the object does not support that particular member.

Example

The following example demonstrates how a behavior that implements mouseover highlighting effect could be dynamically attached to all LI elements on a page.

<script language="JScript">
function window.onload ( ) {
oColl = document.all.tags ( "LI" );
if ( oColl != null ) {
  for ( i=0; i < oColl.length; i++ ) {
    oColl ( i ).addBehavior ( 
    "sample/hilite.htc" );
  }
}
}
</script>

<UL>
  <LI>HTML Authoring
  <UL>
  <LI>IE 4.0 authoring tips
  :
  </UL>
</UL>
See Also

removeBehavior, DHTML Behaviors Overview, Using DHTML Behaviors, Implementing DHTML Behaviors in Script



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note