Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > Adobe Dreamweaver

  • Print
  • + Share This
This chapter is from the book

Change Property

Change Property is a flexible but oddly uncharming behavior that allows you to let the user's movements affect attributes of many different kinds of tags, from layers, to text, to forms.

The most skeletal of the dialog boxes that Macromedia includes as a Dreamweaver behavior, the Change Property behavior, is not the most intuitive or user-friendly behavior, in terms of the hints it gives you as to how to use it—but it can be quite powerful in the right hands.

In this section, we'll show you how to use the Change Property behavior to change the background color of a layer, the font size of some text, and we'll also look at how to change arbitrary chunks of text.

In these examples, we'll be triggering the behavior by clicking on an image, but you could use any valid event to trigger the Change Property behavior. Again, consult Tarin's Macromedia Dreamweaver MX for Windows and Macintosh: Visual QuickStart Guide for more detail on the possible events.

To change the background color of a layer:

  1. Create a new HTML file.

  2. Insert an image onto the page.

  3. From the menu bar, choose Insert > Layer to add a new layer to the page (Figure 13.8).

    Figure 13.8Figure 13.8 The new layer appears at the insertion point.

  4. Add some text to the layer.

  5. Select the image you inserted earlier.

  6. In the Behaviors panel, click on the + (plus) button and select Change Property from the drop-down menu.

    The Change Property dialog box will appear (Figure 13.9).

    Figure 13.9Figure 13.9 The Change Property dialog box is center stage for all work you'll do with the Change Property behavior.

  7. From the Type of Object drop-down menu, select DIV.

  8. From the Named Object drop-down menu, select div "Layer 1".

  9. In the first Property drop-down menu, select style.backgroundColor.

  10. In the New Value text box, enter #CC0000. Your dialog box should now look something like Figure 13.10.

    Figure 13.10Figure 13.10 Here, we're changing the background color of a layer.

  11. Click OK to close the dialog box.

  12. In the Behaviors panel, click on the down arrow next to the behavior and select onClick from the drop-down menu.

  13. Preview the page in your browser. Click on the image. The layer background should turn red (Figure 13.11).

    Figure 13.11Figure 13.11 Mouse over the image, and the layer's background color changes. (If this book were in color, the new background would be red, not gray.)


That wasn't too hard, was it? Don't worry, it gets harder!

The next two examples are going to require a little HTML tinkering. We'll be using the <span> tag, which is an arbitrary container for HTML. We call it arbitrary because it's meant as a marker for applying styles and it doesn't do anything by itself, unlike, say, a <p> tag, which adds a blank line of space on the page before and after the tag.

To add a <span> to your page:

  1. Type some text onto an HTML page.

  2. In Code view, click before the text you want to include in the span, and type <span id="testspan">, and then type </span> after the text you want to include (Figure 13.12).

    Figure 13.12Figure 13.12 Wrapping a <span> tag around HTML or text makes the span contents modifiable in JavaScript. It also doesn't innately affect the visual presentation of the text.

  3. Press F5 to refresh the design view. It shouldn't look any different.

Now that your text is enclosed in a span, you can change various properties of it using the Change Property behavior.

To change the size of the text:

  1. Add a span of text to your page, as in the previous list.

  2. Add an image to your page.

  3. Select the image.

  4. In the Behaviors panel, click on the + (plus) button and select Change Property from the drop-down menu.

    The Change Property dialog box will appear.

  5. In the Type of Object drop-down menu, select SPAN.

  6. In the Named Object drop-down, select the named span you added to the page.

  7. From the Property drop-down menu, select style.fontSize.

  8. In the New Value text box, enter 36 (Figure 13.13).

    Figure 13.13Figure 13.13 As is often the case with test pages, we're choosing obvious formatting changes over sumptuous typography.

  9. Click OK to close the dialog box.

  10. In the Behaviors panel, click on the down arrow next to the behavior and select onClick from the drop-down menu.

  11. Preview your file in a browser. Click on the image. The text size should change (Figure 13.14).

    Figure 13.14Figure 13.14 See?


In addition to twiddling the size, color or face of the font in a span, you can also change the actual text inside a span. If you're willing to muck around with the HTML a little bit, you can even use JavaScript to fill in the text.

We'll look at how to use Change Property to display the current date and time.

To change the text in a span:

  1. Follow Steps 1 through 6 in the previous list.

  2. From the Property drop-down menu, select innerHTML.

  3. In the New Value text box, enter Date(). Your dialog box should resemble Figure 13.15.

    Figure 13.15Figure 13.15 You have to jigger the code a little to get the actual date to show up.

  4. Click OK to close the dialog box.

  5. In the Behaviors panel, click on the down arrow next to the behavior and select onClick from the drop-down menu.

  6. Preview the file in your browser and click on the image.

    You'll get little or no reaction. That's clearly not what we want, so we need to tweak the file a little.

  7. In Code view, find the code that calls the behavior.

    It should be something like

    onClick="MM_changeProp('test','',
    'innerHTML','Date()','SPAN')".
  8. Delete the single quotes that surround Date().

  9. Preview the file again in your browser. Now you should get something like Figure 13.16.

    Figure 13.16Figure 13.16 Consult a good JavaScript reference to see how to format the date the way you want it.


  • + Share This
  • 🔖 Save To Your Account