Share via


id Property

Returns or sets a String that represents the value of the id attribute for an HTML element.

expression.id

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

Remarks

The value of the id property is used when programmatically accessing an element in a document. Therefore, the id attribute for an element should be unique throughout the scope of the document. For example, the following code would access the TABLE element in the active document that has an id attribute equal to "regions". If none is found, the object variable objTable is equal to Nothing.

Dim objTable As FPHTMLTable
Set objTable = ActiveDocument.all.tags("table").Item("regions")

If a document contains more than one element with the same id attribute, the elements are returned as an IHTMLElementCollection collection that can be referenced only by using the ordinal position. For example, the following example returns a collection of paragraphs with an id attribute equal to "intro" and then accesses the first paragraph in that collection by using its ordinal position.

Dim objParas As IHTMLElementCollection
Dim objPara As FPHTMLParaElement
Set objParas = ActiveDocument.all.tags("P").Item("intro")
Set objPara = objParas.Item(0)

Example

The following example adds "intropara" to the first paragraph in the active document.

ActiveDocument.all.tags("P").Item(0).Id = "intropara"