• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Lesson 7. Using Libraries > Creating a Library Item Containing Behaviors

Creating a Library Item Containing Behaviors

Library items must be contained within the <BODY> of the document and cannot contain or reference any items outside of the <BODY> (unless the items referenced are in the containing HTML file). For this reason, JavaScript cannot be used in library items if the script requires code between the <HEAD> and </HEAD> tags of the document, because those tags are located before the <BODY> tag. There is one exception however: because behaviors are predefined JavaScripts for which Dreamweaver will insert the corresponding JavaScript functions into the <HEAD>, you can use Dreamweaver's behaviors in library items, even though the necessary JavaScript requires code to be placed between the <HEAD> and </HEAD> tags of the document. Although the code that is required in the <HEAD> is not included in the library item, Dreamweaver will automatically place the code into the <HEAD> whenever the library item is placed into a document.

1.
Open road.htm and select the table at the top of the document.

This table contains a rollover that was created using Dreamweaver's Insert Rollover function. Insert Rollover and other behaviors were covered in Lesson 5.

2.
Click the new library item button at the bottom of the Library panel. Type header for the new library item name and press Enter (Windows) or Return (Macintosh).

The library item contains certain portions of the code necessary for the behavior, including the event handler, as well as the action to call when the event occurs. It does not contain any of the functions that are required to be placed between the <HEAD> and </HEAD> tags of the document.

3.
Insert this new library item at the top of the page in the biking.htm document.

The JavaScript functions that are required for the rollover in this library item are automatically inserted between the <HEAD> and </HEAD> tags of the document. While these functions are not included in the library item, they are inserted because Dreamweaver recognizes certain portions of the code in the library item as behaviors and automatically inserts the required code into the <HEAD>.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint