HtmlOptionElement
sealed class HtmlOptionElement : HtmlElement, IHtmlOptionElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle
Represents the HTML option element.
using AngleSharp.Dom.Css;
using AngleSharp.Extensions;
using AngleSharp.Html;
namespace AngleSharp.Dom.Html
{
internal sealed class HtmlOptionElement : HtmlElement, IHtmlOptionElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle
{
private bool? _selected;
public bool IsDisabled {
get {
return GetOwnAttribute(AttributeNames.Disabled) != null;
}
set {
SetOwnAttribute(AttributeNames.Disabled, value ? string.Empty : null);
}
}
public IHtmlFormElement Form => GetAssignedForm();
public string Label {
get {
return GetOwnAttribute(AttributeNames.Label) ?? Text;
}
set {
SetOwnAttribute(AttributeNames.Label, value);
}
}
public string Value {
get {
return GetOwnAttribute(AttributeNames.Value) ?? Text;
}
set {
SetOwnAttribute(AttributeNames.Value, value);
}
}
public int Index {
get {
HtmlOptionsGroupElement htmlOptionsGroupElement = base.Parent as HtmlOptionsGroupElement;
if (htmlOptionsGroupElement != null) {
int num = 0;
foreach (INode childNode in htmlOptionsGroupElement.ChildNodes) {
if (object.ReferenceEquals(childNode, this))
return num;
num++;
}
}
return 0;
}
}
public string Text {
get {
return TextContent.CollapseAndStrip();
}
set {
TextContent = value;
}
}
public bool IsDefaultSelected {
get {
return GetOwnAttribute(AttributeNames.Selected) != null;
}
set {
SetOwnAttribute(AttributeNames.Selected, value ? string.Empty : null);
}
}
public bool IsSelected {
get {
if (!_selected.HasValue)
return IsDefaultSelected;
return _selected.Value;
}
set {
_selected = value;
}
}
public HtmlOptionElement(Document owner, string prefix = null)
: base(owner, Tags.Option, prefix, NodeFlags.ImplicitelyClosed | NodeFlags.ImpliedEnd | NodeFlags.HtmlSelectScoped)
{
}
}
}