Sets or retrieves the location of the Dynamic HTML (DHTML) behavior.
Syntax
HTML { behavior : sBehavior } Scripting object.style.behavior [ = sBehavior ]
Possible Values
sBehavior String that specifies one of the following values:
url(sLocation) Script implementation of a DHTML behavior, where sLocation is an absolute or relative URL. url(#objID) Binary implementation of a DHTML behavior, where objID is the ID attribute specified in an OBJECT tag. url(#default#behaviorName) One of Internet Explorer's default behaviors, identified by its behaviorName. The property is read/write with no default value; the proposed cascading style sheets (CSS) extension attribute is not inherited.
Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see Dynamic Properties.
Remarks
You can apply multiple behaviors to an element by specifying a space-delimited list of URLs for the behavior attribute, as shown in the following syntax:
<ELEMENT STYLE="behavior:url(a1.htc) url(a2.htc) ..." >In the following Example section, one example demonstrates how two behaviors can be applied 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 in the order. 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 behavior property has been defined for the element, the addBehavior method can be used to dynamically attach additional behaviors to the element.
Note A behavior attached to an element by using the addBehavior method or by applying the proposed CSS 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.
Example
The following examples demonstrate various ways of applying the behavior property on a page.
Sample Code
This example implements an expanding/collapsing table of contents by applying the behavior as an inline style to the LI element. In this particular case, two behaviors implemented as HTML Components (HTC) have been applied to the element to achieve a combination of mouseover highlighting and expanding/collapsing effects.
<UL> <LI STYLE="behavior:url(ul.htc) url(hilite.htc)">HTML</LI> <UL> <LI>IE 4.0 authoring tips</LI> : </UL> </UL>This same example defines the behavior attribute in a separate <STYLE> block.
<style> .CollapsingAndHiliting {behavior:url(ul.htc) url(hilite.htc)} </style> <UL> <LI CLASS="CollapsingAndHiliting">HTML</LI> <UL> <LI>IE 4.0 authoring tips</LI> : </UL> </UL>This example sets the behavior property in script.
<SCRIPT> function window.onload() { idTopic1.style.behavior = "url(ul.htc) url(hilite.htc)"; } </SCRIPT> : <UL> <LI ID=idTopic1>HTML Authoring</LI> <UL> <LI>IE 4.0 authoring tips</LI> : </UL> </UL>This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
If the same 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 behavior attribute points to the ID property of the object specified in the <OBJECT> tag.
<STYLE> .Collapsing { behavior:url(#myObject) } </STYLE> <OBJECT ID=myObject ... ></OBJECT> <UL> <LI CLASS="Collapsing">HTML Authoring</LI> <UL> <LI>IE 4.0 authoring tips</LI> : </UL> </UL>
Applies To
A, ACRONYM, ADDRESS, APPLET, AREA, B, BASE, BASEFONT, BGSOUND, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, COMMENT, custom, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, FRAMESET, HEAD, Hn, HR, HTML, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, ISINDEX, KBD, LABEL, LEGEND, LI, LINK, LISTING, MAP, MARQUEE, MENU, NEXTID, NOBR, NOFRAMES, NOSCRIPT, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, RT, RUBY, S, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, STYLE, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TITLE, TR, TT, U, UL, VAR, WBR, XML, XMP
See Also
Using DHTML Behaviors