behavior property

Sets or retrieves the location of the Dynamic HTML (DHTML) behaviorDHTML Behaviors.


Integer value = object.put_behavior( v);Integer value = object.get_behavior(* sBehavior);

Property values

Type: BSTR

url(sLocation) (url(sLocation))

Script implementation of a DHTML behavior, where sLocation is an absolute or relative URL.

url(#objID) (url(#objID))

Binary implementation of a DHTML behavior, where objID is the IHTMLElement::id attribute specified in an object tag.

url(#default#behaviorName) (url(#default#behaviorName))

The application's  default behavior, identified by its behaviorName.

String format

url(sLocation) | url(#objID) | url(#default#behaviorName)

CSS information

Applies To All elements
Media visual
Inherited no
Initial Value none


Windows Internet Explorer 8. The IHTMLCSSStyleDeclaration::behavior attribute is an extension to CSS, and can be used as a synonym for behavior in IE8 Standards mode.

You can apply multiple behaviors to an element by specifying a space-delimited list of URLs for the IHTMLCSSStyleDeclaration::behavior attribute, as shown in the following syntax:

<element style="behavior:url( url( ..." >

In the following section, one example demonstrates how you can apply two behaviors to an element to achieve a combination of effects. Conflicts resulting from applying multiple behaviors to an element are resolved based on the order in which the behavior is applied to the element. Each succeeding behavior takes precedence over the previous behavior. For example, if multiple behaviors set the element's color, the prevailing color is the one set by the behavior last applied to the element. The same rule applies in resolving name conflicts, such as with property, method, or event names exposed by multiple behaviors.

Once the IHTMLCSSStyleDeclaration::behavior property is defined for the element, the IHTMLElement2::addBehavior method can be used to dynamically attach additional behaviors to the element.

Note  A behavior attached to an element by using the IHTMLElement2::addBehavior method or by applying the proposed Cascading Style Sheets (CSS) IHTMLCSSStyleDeclaration::behavior attribute inline is not automatically detached from the element when the element is removed from the document hierarchy. However, a behavior attached using a style rule defined in the document is detached automatically as the element is removed from the document tree.



The following examples demonstrate various ways of applying the IHTMLCSSStyleDeclaration::behavior property on a page.

This example implements an expanding and collapsing table of contents by applying the behavior as an inline style to the li element. In this case, two behaviors implemented as HTC have been applied to the element to achieve a combination of mouseover highlighting and expanding/collapsing effect.

  <li style="behavior:url( url(">HTML</li>
      <li>Internet Explorer authoring tips</li>

This example sets the IHTMLCSSStyleDeclaration::behavior property in script.

Code example:

   function window.onload()
   { = "url( url(";
  <li id=idTopic1>HTML Authoring</li>
      <li>Internet Explorer authoring tips</li>

If the expanding/collapsing example were to use a DHTML behavior implemented in C++ as an ActiveX control, the code would look slightly different. In this example, the IHTMLCSSStyleDeclaration::behavior attribute points to the IHTMLElement::id property of the object specified in the object element.

   .Collapsing { behavior:url(#myObject) }
<object id=myObject ... ></object>
  <li class="Collapsing">HTML Authoring</li>
      <li>Internet Explorer authoring tips</li>


Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003







See also


Using DHTML Behaviors

Other Resources

Behavioral Extensions to CSS