HtmlDocument.GetElementById Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets a single browser element.

Namespace:  System.Windows.Browser
Assembly:  System.Windows.Browser (in System.Windows.Browser.dll)


<SecuritySafeCriticalAttribute> _
Public Function GetElementById ( _
    id As String _
) As HtmlElement
public HtmlElement GetElementById(
    string id


  • id
    Type: System.String
    A string identifier for a named browser element.

Return Value

Type: System.Windows.Browser.HtmlElement
A reference to a browser element.


Exception Condition

id is an empty string.


id is nulla null reference (Nothing in Visual Basic).


An unexpected error occurred.


If the specified HTML element cannot be found, this method returns nulla null reference (Nothing in Visual Basic).

The following example uses the GetElementById method to get a reference to an HTML element named "Button123456". If this element does not exist, the variable named el is set to nulla null reference (Nothing in Visual Basic) and an error message is displayed.

HtmlDocument htmlDoc = HtmlPage.Document;
HtmlElement el = htmlDoc.GetElementById("Button123456");
If (el == null)
    HtmlPage.window.Alert("el is null");

Version Information


Supported in: 5, 4, 3


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.