Document.GetElementById

Document.GetElementById method

This method returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they’re a useful way to get access to a specific element quickly.

If you need to get access to an element which doesn’t have an ID, you can use QuerySelector to find the element using any selector.

public Element GetElementById(string elementId)
ParameterTypeDescription
elementIdStringThe ID of the element to locate. The ID is case-sensitive string which is unique within the document; only one element may have any given ID.

Return Value

An Element object describing the DOM element object matching the specified ID, or null if no matching element was found in the document.

Remarks

Refer to official spec.

See Also