How to access the name of an HTML element at run-time?
9 Dec 2019 / 1 minute to read
The element.Name property gets the name of the tag that defines the element as an attribute, and not the name of the element defined by the user. You can access the name of the element with the help of the element.Attributes property.
The following HTML document illustrates how an input element with a name is declared and accessed in HTMLUI.
<html>
<body>
<p>
<input type="text" id="txt1" name="textboxOne" size="20"></input>
</p>
</body>
</html>
INPUTElementImpl textBox1;
Hashtable tab = this.htmluiControl1.Document.GetElementsByUserIdHash();
//accessing the input element
textBox1 = tab["txt1"] as INPUTElementImpl;
//accessing the tag name of the element
Console.WriteLine("Tag Name of TextBox1:\n"+ textBox1.Name.ToString());
//accessing the attribute name of the element
Console.WriteLine("Name given for TextBox1:\n"+ textBox1.Attributes["name"].Value);
Private textBox1 As INPUTElementImpl
Private tab As Hashtable = Me.htmluiControl1.Document.GetElementsByUserIdHash()
'accessing the input element
Private textBox1 = CType(IIf(TypeOf tab("txt1") Is INPUTElementImpl,
tab("txt1"), Nothing), INPUTElementImpl)
'accessing the tag name of the element
Console.WriteLine("Tag Name of TextBox1:" & Constants.vbLf+ textBox1.Name.ToString())
'accessing the attribute name of the element
Console.WriteLine("Name given for TextBox1:" & Constants.vbLf+ textBox1.Attributes("name").Value)
Was this page helpful?
Yes
No
Thank you for your feedback!
Thank you for your feedback and comments. We will rectify this as soon as possible!
An unknown error has occurred. Please try again.
Help us improve this page