behaviorElement Property

Returns an IHTMLElement object that represents the top-most parent element of active selection. Corresponds to the element specified for Scripts on Tag as shown in the Behaviors task pane.

expression.behaviorElement

*expression   * Required. An expression that returns one of the objects in the Applies To list.

Remarks

If the insertion point is in the middle of a P element, the behaviorElement property returns the P element. If a selection spans a few table rows, the behaviorElement property returns the parent TABLE element, since that is the top-most parent element of the selection. If a selection spans the entire document, the behaviorElement property would return the BODY element.

Example

The following example adds a script to the top-most parent element of the active selection in the active document.

  Dim objElement As IHTMLElement

Set objElement = ActiveDocument.behaviorElement

ActiveDocument.addScript objElement, _
    "onclick", "this.innerText=prompt" & _
    "('Please enter your name:', '')"

Applies to | FPHTMLDocument Object | IFPDocument Object | IFPDocument Object