Behaviors > Attaching a behavior

 

Attaching a behavior

You can attach behaviors to the entire document (that is, to the body tag) or to links, images, form elements, or any of several other HTML elements. The target browser you choose determines which events are supported for a given element. Internet Explorer 4.0, for example, has a much wider array of events for each element than Navigator 4.0 or any 3.0 browser.

Note: You can't attach a behavior to plain text. For details, see About behaviors and text.

You can specify more than one action for each event. Actions occur in the order in which they're listed in the Actions column of the Behaviors panel. For information on changing the order of actions, see Changing a behavior.

To attach a behavior:

1 Select an element on the page, such as an image or a link.
To attach a behavior to the entire page, click the <body> tag in the tag selector at the bottom left of the Document window.
2 Choose Window > Behaviors to open the Behaviors panel.
The HTML tag of the selected object appears in the title bar of the Behavior panel.
3 Click the Plus (+) button and choose an action from the Actions pop-up menu.
Actions that are dimmed in the menu can't be chosen. They may be dimmed because a required object doesn't exist in the current document. For example, the Play Timeline action is dimmed if the document has no timelines, and the Control Shockwave or Flash action is dimmed if the document contains no Shockwave or Flash movies. If no events are available for the selected object, all actions are dimmed.
When you choose an action, a dialog box appears, displaying parameters and instructions for the action.
4 Enter parameters for the action, and click OK.
All actions provided in Dreamweaver work in 4.0 and later browsers. Some actions do not work in older browsers. See Using the behavior actions that come with Dreamweaver.
5 The default event to trigger the action appears in the Events column. If this is not the trigger event you want, choose another event from the Events pop-up menu. (To open the Events pop-up menu, select an event or action in the Behaviors panel, and click the downward-pointing black arrow that appears between the event name and the action name.)
Different events appear in the Events pop-up menu depending on the selected object and on the browsers specified in the Show Events For submenu. Events may be dimmed if the relevant objects do not yet exist on the page or if the selected object cannot receive events. If the expected events don't appear, make sure the correct object is selected, or change the target browsers in the Show Events For pop-up menu.
If you're attaching a behavior to an image, some events (such as onMouseOver) appear in parentheses. These events are available only for links. When you choose one of them, Dreamweaver wraps an a tag around the image to define a null link. The null link is represented by javascript:; in the Property inspector's Link box. You can change the link value if you want to turn it into a real link to another page, but if you delete the JavaScript link without replacing it with another link, you will remove the behavior.