次の方法で共有


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)

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Function GetElementById ( _
    id As String _
) As HtmlElement
[SecuritySafeCriticalAttribute]
public HtmlElement GetElementById(
    string id
)

Parameters

  • 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.

Exceptions

Exception Condition
ArgumentException

id is an empty string.

ArgumentNullException

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

InvalidOperationException

An unexpected error occurred.

Remarks

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

Silverlight

Supported in: 5, 4, 3

Platforms

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