Reusing Content with Templates and Libraries > Creating, managing, and editing library items > Editing a behavior in a library item |
Editing a behavior in a library item
When you create a library item that includes an element with a Dreamweaver behavior attached to it, Dreamweaver copies the element and its event handler (the attribute that specifies which event triggers the action (such as onClick
, onLoad
, or onMouseOver
), and which action to call when the event occurs) to the library item file. Dreamweaver does not copy the associated JavaScript functions into the library item. Instead, when you insert the library item into a document, Dreamweaver automatically inserts the appropriate JavaScript functions into the head
section of that document (if they aren't already there).
Note: If you hand-code JavaScript (that is, if you create it without using Dreamweaver behaviors), you can make it part of a library item if you use the Call JavaScript behavior to execute the code. If you don't use a Dreamweaver behavior to execute the code, the code isn't retained as part of the library item.
The JavaScript functions are not stored with the library item because they are elements of the head
section of the document, while library items can only contain body
elements. Thus, the Behaviors panel is unavailable when you are editing a library item, because only part of the behavior code (the event handler) is included in the library item. To edit a behavior in a library item, you must first insert the item in a document, then make the item editable in that document. After you've made the desired changes, you can re-create the library item, replacing the item in the library with the edited item from your document.
For more information about behaviors, see Behaviors overview.
To edit a behavior in a library item:
1 | Open a document that contains the library item. |
Note the name of the library item, as well as the exact tags it contains. You'll need this information in steps 8 and 9. | |
2 | Select the library item and click Detach from Original in the Property inspector. |
3 | Select the element that has the behavior attached to it. |
4 | Choose Window > Behaviors to open the Behaviors panel. In the Behaviors panel, double-click the action you want to change. |
5 | In the dialog box that appears, make the necessary changes and click OK. |
6 | Choose Window > Library to open the Library category of the Assets panel. |
7 | Make sure you have recorded the exact name of the original library item; then select the original library item, and delete it by clicking the Delete button in the Assets panel. |
8 | In the Document window, select all of the elements that make up the library item. |
Be careful to select exactly the same elements that were in the original library item. | |
9 | In the Assets panel, click the New Library Item button, and give the new item the same name as the item you deleted in step 7. |
Be sure to use exactly the same spelling and capitalization. | |
10 | To update the library item in your site's other documents, choose Modify > Library > Update Pages. |
11 | In the Update Pages dialog box, in the Look in pop-up menu, select Files That Use. |
12 | In the adjacent pop-up menu, choose the name of the library item you just created. |
13 | In the Update option, make sure Library Items is selected, and then click Start. |
14 | When the updates are complete, click Close to exit the Update Pages dialog box. |