Interface IElement
- Namespace
- AngleSharp.Dom
- Assembly
- AngleSharp.dll
The Element interface represents an object within a DOM document.
[DomName("Element")]
public interface IElement : INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode
- Inherited Members
- Extension Methods
Properties
AssignedSlot
Gets the assigned slot of the current element, if any.
[DomName("assignedSlot")]
IElement? AssignedSlot { get; }
Property Value
Attributes
Gets the sequence of associated attributes.
[DomName("attributes")]
INamedNodeMap Attributes { get; }
Property Value
ClassList
Gets the list of class names.
[DomName("classList")]
ITokenList ClassList { get; }
Property Value
ClassName
Gets or sets the value of the class attribute.
[DomName("className")]
string? ClassName { get; set; }
Property Value
GivenNamespaceUri
Gets the given namespace URI of this element. This one will not be resolved via its parent, but only yields the provided namespace, if any.
string? GivenNamespaceUri { get; }
Property Value
Id
Gets or sets the id value of the element.
[DomName("id")]
string? Id { get; set; }
Property Value
InnerHtml
Gets or sets the inner HTML (excluding the current element) of the element.
[DomName("innerHTML")]
string InnerHtml { get; set; }
Property Value
IsFocused
Gets if the element is currently focused.
bool IsFocused { get; }
Property Value
LocalName
Gets the local part of the qualified name of this element.
[DomName("localName")]
string LocalName { get; }
Property Value
NamespaceUri
Gets the namespace URI of this element.
[DomName("namespaceURI")]
string? NamespaceUri { get; }
Property Value
OuterHtml
Gets or sets the outer HTML (including the current element) of the element.
[DomName("outerHTML")]
string OuterHtml { get; set; }
Property Value
Prefix
Gets the namespace prefix of this element.
[DomName("prefix")]
string? Prefix { get; }
Property Value
ShadowRoot
Gets the shadow root of the current element, if any.
[DomName("shadowRoot")]
IShadowRoot? ShadowRoot { get; }
Property Value
Slot
Gets the value of the slot attribute.
[DomName("slot")]
string? Slot { get; set; }
Property Value
SourceReference
Gets the source reference if available.
ISourceReference? SourceReference { get; }
Property Value
TagName
Gets the name of the tag that represents the current element.
[DomName("tagName")]
string TagName { get; }
Property Value
Methods
AttachShadow(ShadowRootMode)
Creates a new shadow root for the current element, if there is none already.
[DomName("attachShadow")]
[DomInitDict(0, false)]
IShadowRoot AttachShadow(ShadowRootMode mode = ShadowRootMode.Open)
Parameters
mode
ShadowRootModeThe mode of the shadow root.
Returns
- IShadowRoot
The new shadow root.
Closest(string)
Returns the closest ancestor of the current element (or the current element itself) which matches the selectors given in the parameter.
[DomName("closest")]
IElement? Closest(string selectors)
Parameters
selectors
stringRepresents the selector to test.
Returns
- IElement
The closest ancestor of the current element (or the current element itself) which matches the selectors given. If there isn't such an ancestor, it returns null.
GetAttribute(string)
Returns the value of the named attribute on the specified element.
[DomName("getAttribute")]
string? GetAttribute(string name)
Parameters
name
stringThe name of the attribute whose value you want to get.
Returns
- string
If the named attribute does not exist, the value returned will be null, otherwise the attribute's value.
GetAttribute(string?, string)
Returns the value of the named attribute on the specified element.
[DomName("getAttributeNS")]
string? GetAttribute(string? namespaceUri, string localName)
Parameters
namespaceUri
stringA string specifying the namespace of the attribute.
localName
stringThe name of the attribute whose value you want to get.
Returns
- string
If the named attribute does not exist, the value returned will be null, otherwise the attribute's value.
GetElementsByClassName(string)
Returns a set of elements which have all the given class names.
[DomName("getElementsByClassName")]
IHtmlCollection<IElement> GetElementsByClassName(string classNames)
Parameters
classNames
stringA string representing the list of class names to match; class names are separated by whitespace.
Returns
- IHtmlCollection<IElement>
A collection of elements.
GetElementsByTagName(string)
Returns a NodeList of elements with the given tag name. The complete document is searched, including the root node.
[DomName("getElementsByTagName")]
IHtmlCollection<IElement> GetElementsByTagName(string tagName)
Parameters
tagName
stringA string representing the name of the elements. The special string "*" represents all elements.
Returns
- IHtmlCollection<IElement>
A collection of elements in the order they appear in the tree.
GetElementsByTagNameNS(string?, string)
Returns a list of elements with the given tag name belonging to the given namespace. The complete document is searched, including the root node.
[DomName("getElementsByTagNameNS")]
IHtmlCollection<IElement> GetElementsByTagNameNS(string? namespaceUri, string tagName)
Parameters
namespaceUri
stringThe namespace URI of elements to look for.
tagName
stringEither the local name of elements to look for or the special value "*", which matches all elements.
Returns
- IHtmlCollection<IElement>
A collection of elements in the order they appear in the tree.
HasAttribute(string)
Returns a boolean value indicating whether the specified element has the specified attribute or not.
[DomName("hasAttribute")]
bool HasAttribute(string name)
Parameters
name
stringThe attributes name.
Returns
- bool
The return value of true or false.
HasAttribute(string?, string)
Returns a boolean value indicating whether the specified element has the specified attribute or not.
[DomName("hasAttributeNS")]
bool HasAttribute(string? namespaceUri, string localName)
Parameters
namespaceUri
stringA string specifying the namespace of the attribute.
localName
stringThe attributes name.
Returns
- bool
The return value of true or false.
Insert(AdjacentPosition, string)
Inserts new HTML elements specified by the given HTML string at a position relative to the current element specified by the position.
[DomName("insertAdjacentHTML")]
void Insert(AdjacentPosition position, string html)
Parameters
position
AdjacentPositionThe relation to the current element.
html
stringThe HTML code to generate elements for.
Matches(string)
Checks if the element is matched by the given selector.
[DomName("matches")]
bool Matches(string selectors)
Parameters
selectors
stringRepresents the selector to test.
Returns
- bool
True if the element would be selected by the specified selector, otherwise false.
RemoveAttribute(string)
Removes an attribute from the specified element.
[DomName("removeAttribute")]
bool RemoveAttribute(string name)
Parameters
name
stringIs a string that names the attribute to be removed.
Returns
- bool
True if an attribute was removed, otherwise false.
RemoveAttribute(string?, string)
Removes an attribute from the specified element.
[DomName("removeAttributeNS")]
bool RemoveAttribute(string? namespaceUri, string localName)
Parameters
namespaceUri
stringA string specifying the namespace of the attribute.
localName
stringIs a string that names the attribute to be removed.
Returns
- bool
True if an attribute was removed, otherwise false.
SetAttribute(string, string?)
Adds a new attribute or changes the value of an existing attribute on the specified element.
[DomName("setAttribute")]
void SetAttribute(string name, string? value)
Parameters
name
stringThe name of the attribute as a string.
value
stringThe desired new value of the attribute.
SetAttribute(string?, string, string?)
Adds a new attribute or changes the value of an existing attribute on the specified element.
[DomName("setAttributeNS")]
void SetAttribute(string? namespaceUri, string name, string? value)