insertAdjacentHTML Method

Inserts HTML text into a document at the specified location.

expression.insertAdjacentHTML(where, html)

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

Can be one of the following values

beforeBegin Inserts the specified HTML text immediately before the opening element of the object.
afterBegin Inserts the specified HTML text immediately after the opening element of the object but before all other content in the object.
beforeEnd Inserts the specified HTML text immediately before the end of the object but after all other content in the object.
afterEnd Inserts the specified HTML text immediately after the end of the object.

The following image illustrates where text or HTML is inserted when you use each of the above String values.

The inner/outer properties.

html    Required. String that specifies the HTML text to insert. The string can be a combination of text and HTML tags. This must be valid, well-formed HTML.


Use the insertAdjacentText method to insert text without providing the accompanying HTML tags. In addition, you can use the outerHTML and outerText properties to insert HTML and text outside the specified element, and the innerHTML and innerText properties to insert HTML and text inside the specified element. The following image illustrates where each of these properties applies. Note that the innerHTML and outerHTML properties require well-formed HTML.



The following example inserts the date when the specified document was last modified into the specified document and formats it with the specified font name, font size, and color.

Sub AddModifiedDateToDocument(objDoc As FPHTMLDocument, strFont As String, _
        strSize As String, strColor As String)
    Dim objFont As FPHTMLFontElement
    objDoc.body.insertAdjacentHTML where:="beforeEnd", _
        HTML:="<p><font id=""modifiedon""></font></p>"
    Set objFont = objDoc.body.all.tags("font").Item("modifiedon")
    objFont.insertAdjacentText where:="beforeEnd", Text:="Last modified on: " _
        & objDoc.fileModifiedDate
    With objFont
        .face = strFont
        .Size = strSize
        .Color = strColor
    End With
End Sub

Use the following example to call the preceding example.

Sub CallAddModifiedDateToDocument()
    Call AddModifiedDateToDocument(ActiveDocument, "Arial", "2", "Blue")
End Sub

Applies to | FPHTMLAnchorElement Object | FPHTMLAreaElement Object | FPHTMLBaseElement Object | FPHTMLBaseFontElement Object | FPHTMLBGsound Object | FPHTMLBlockElement Object | FPHTMLBody Object | FPHTMLBRElement Object | FPHTMLButtonElement Object | FPHTMLCommentElement Object | FPHTMLDDElement Object | FPHTMLDivElement Object | FPHTMLDivPosition Object | FPHTMLDListElement Object | FPHTMLDTElement Object | FPHTMLEmbed Object | FPHTMLFieldSetElement Object | FPHTMLFontElement Object | FPHTMLFormElement Object | FPHTMLFrameBase Object | FPHTMLFrameElement Object | FPHTMLFrameSetSite Object | FPHTMLFrontPageBotElement Object | FPHTMLHeaderElement Object | FPHTMLHRElement Object | FPHTMLIFrame Object | FPHTMLImg Object | FPHTMLInputButtonElement Object | FPHTMLInputFileElement Object | FPHTMLInputHiddenElement Object | FPHTMLInputImage Object | FPHTMLInputTextElement Object | FPHTMLIsIndexElement Object | FPHTMLLabelElement Object | FPHTMLLegendElement Object | FPHTMLLIElement Object | FPHTMLLinkElement Object | FPHTMLListElement Object | FPHTMLMapElement Object | FPHTMLMarqueeElement Object | FPHTMLMetaElement Object | FPHTMLNextIdElement Object | FPHTMLNoShowElement Object | FPHTMLObjectElement Object | FPHTMLOListElement Object | FPHTMLOptionElement Object | FPHTMLParaElement Object | FPHTMLPhraseElement Object | FPHTMLScriptElement Object | FPHTMLSelectElement Object | FPHTMLSpanElement Object | FPHTMLSpanFlow Object | FPHTMLStyleElement Object | FPHTMLTable Object | FPHTMLTableCaption Object | FPHTMLTableCell Object | FPHTMLTableCol Object | FPHTMLTableRow Object | FPHTMLTableSection Object | FPHTMLTemplateRegionElement Object | FPHTMLTextAreaElement Object | FPHTMLTextElement Object | FPHTMLTitleElement Object | FPHTMLUListElement Object | FPHTMLUnknownElement Object | FPHTMLWebPartElement Object | FPHTMLWebPartZoneElement Object | FPHTMLXSLElement Object | FPHTMLXSLWebPartElement Object | IHTMLElement Object