tags Method

Microsoft FrontPage Visual Basic

tags Method

Returns an IHTMLElementCollection collection that represents a collection of specific HTML elements that are contained within the specified object.

expression.tags(tagName)

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

tagName   Required Variant. Specifies the name of the HTML element.

Remarks

Use the all property to return a collection of all HTML elements within a specified object and then use the tags method to return a collection of elements of a specific type. For example, in the following line, the tags method returns a collection of P elements in the active document.

ActiveDocument.all.tags("p")

Once you've returned the collection of elements, you can use the item method to specify which element in the collection you want to work with. For example, in the following line, the item method returns the first paragraph in the collection of P elements in the active document.

ActiveDocument.all.tags("p").Item(0)

Example

The following example inserts a list box into the active document and then uses the tags method to return a collection of SELECT elements and the item method to return the specific SELECT element that represents the newly added list box.

    Sub AddListBox()
    Dim objListBox As FPHTMLSelectElement
    Dim strHTML As String
    
    strHTML = "<SELECT ID=""pets"">" & "<OPTION VALUE=""1"">Cat" & _
        vbCrLf & "<OPTION VALUE=""2"">Dog" & vbCrLf & _
        "<OPTION VALUE=""3"">Snake" & vbCrLf & "</SELECT>"

    ActiveDocument.body.insertAdjacentHTML _
        where:="beforeend", HTML:=strHTML
        
    Set objListBox = ActiveDocument.all.tags("select").Item("pets")
    
    With objListBox
        .multiple = True
        .Size = "6"
        .onchange = "fnChange()"
    End With
End Sub