Class HtmlElement
Represents an HTML element in the Document Object Model (DOM) of a Web page.
Implements
Inherited Members
Namespace: System.Windows.Browser
Assembly: OpenSilver.Browser.dll
Syntax
public sealed class HtmlElement : HtmlObject, IDynamicMetaObjectProvider
Properties
| Improve this Doc View SourceChildren
Gets a read-only collection of HTML elements that are immediate descendants of the current HTML element.
Declaration
public ScriptObjectCollection Children { get; }
Property Value
Type | Description |
---|---|
ScriptObjectCollection | A collection of HTML elements. If the current HTML element has no children, the returned collection is empty. |
CssClass
Gets or sets the cascading style sheet (CSS) class string for the current HTML element.
Declaration
public string CssClass { get; set; }
Property Value
Type | Description |
---|---|
System.String | A CSS class string if the element is associated with a CSS class; otherwise, an empty string. |
Id
Gets the identifier of the current HTML element.
Declaration
public string Id { get; set; }
Property Value
Type | Description |
---|---|
System.String | An HTML element ID string if the current element has an identifier; otherwise, an empty string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | The property is set to an empty string. |
System.ArgumentNullException | The property is set to null. |
Parent
Gets a reference to the parent of the current HTML element.
Declaration
public HtmlElement Parent { get; }
Property Value
Type | Description |
---|---|
HtmlElement | An HTML element reference if the element has a parent; otherwise, null. |
TagName
Gets the HTML tag name of the current HTML element.
Declaration
public string TagName { get; }
Property Value
Type | Description |
---|---|
System.String | An HTML element tag name, such as div or span. |
Methods
| Improve this Doc View SourceAppendChild(HtmlElement)
Adds an element to the end of the child collection for the current HTML element.
Declaration
public void AppendChild(HtmlElement element)
Parameters
Type | Name | Description |
---|---|---|
HtmlElement | element | The element to be added. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
System.InvalidOperationException | element is a reference to this HtmlElement. |
AppendChild(HtmlElement, HtmlElement)
Adds an element at a specified location in the child element collection for the current HTML element.
Declaration
public void AppendChild(HtmlElement element, HtmlElement referenceElement)
Parameters
Type | Name | Description |
---|---|---|
HtmlElement | element | The element to be added. |
HtmlElement | referenceElement | The location to insert the element. The element is added before referenceElement. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | referenceElement is not in the child element collection of the current HTML element. |
System.ArgumentNullException | element is null. |
Focus()
Sets the browser focus to the current HTML element.
Declaration
public void Focus()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | All errors. |
GetAttribute(String)
Gets the value of the specified attribute on the current HTML element.
Declaration
public string GetAttribute(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of an attribute. |
Returns
Type | Description |
---|---|
System.String | An attribute on the current HTML element. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | name is an empty string. |
System.ArgumentNullException | name is null. |
GetStyleAttribute(String)
Retrieves the specified style attribute for the current HTML element.
Declaration
public string GetStyleAttribute(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the style attribute to retrieve. |
Returns
Type | Description |
---|---|
System.String | The style attribute for the current HTML element. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | name is an empty string. |
System.ArgumentNullException | name is null. |
RemoveAttribute(String)
Removes an attribute from the current HTML element.
Declaration
public void RemoveAttribute(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the attribute to remove. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | name is an empty string. |
System.ArgumentNullException | name is null. |
RemoveChild(HtmlElement)
Removes the specified element from the child element collection of the current HTML element.
Declaration
public void RemoveChild(HtmlElement element)
Parameters
Type | Name | Description |
---|---|---|
HtmlElement | element | The element to remove. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
System.InvalidOperationException | All other errors. |
RemoveStyleAttribute(String)
Removes a style attribute on the current HTML element.
Declaration
public void RemoveStyleAttribute(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The style attribute to be removed. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | name is an empty string. |
System.ArgumentNullException | name is null. |
SetAttribute(String, String)
Sets the value of an attribute on the current HTML element.
Declaration
public void SetAttribute(string name, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The attribute whose value will be set. |
System.String | value | The attribute's new value. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | name is an empty string. |
System.ArgumentNullException | name is null. |
SetStyleAttribute(String, String)
Sets the value of a style attribute on the current HTML element.
Declaration
public void SetStyleAttribute(string name, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The style attribute whose value will be set. |
System.String | value | The style attribute's new value. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | name is an empty string. |
System.ArgumentNullException | name is null. |