Show / Hide Table of Contents

Class HtmlElement

Represents an HTML element in the Document Object Model (DOM) of a Web page.

Inheritance
System.Object
ScriptObject
HtmlObject
HtmlElement
Implements
System.Dynamic.IDynamicMetaObjectProvider
Inherited Members
HtmlObject.AttachEvent(String, EventHandler)
HtmlObject.AttachEvent(String, EventHandler<HtmlEventArgs>)
HtmlObject.DetachEvent(String, EventHandler)
HtmlObject.DetachEvent(String, EventHandler<HtmlEventArgs>)
HtmlObject.ConvertTo(Type, Boolean)
ScriptObject.Dispatcher
ScriptObject.ManagedObject
ScriptObject.ConvertTo<T>()
ScriptObject.GetProperty(Int32)
ScriptObject.GetProperty(String)
ScriptObject.Invoke(String, Object[])
ScriptObject.InvokeSelf(Object[])
ScriptObject.SetProperty(Int32, Object)
ScriptObject.SetProperty(String, Object)
ScriptObject.IDynamicMetaObjectProvider.GetMetaObject(Expression)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: System.Windows.Browser
Assembly: OpenSilver.Browser.dll
Syntax
public sealed class HtmlElement : HtmlObject, IDynamicMetaObjectProvider

Properties

| Improve this Doc View Source

Children

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 Source

AppendChild(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Focus()

Sets the browser focus to the current HTML element.

Declaration
public void Focus()
Exceptions
Type Condition
System.InvalidOperationException

All errors.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

Implements

System.Dynamic.IDynamicMetaObjectProvider
  • Improve this Doc
  • View Source