<label id="label1" for="txtTextBox">
what is the impact of label1 if I put the for
attribute in there?
It allows you to create a label that is attached to a specific element in the DOM. When the label receives a mouse down event it focuses the element it is attached to.
<label for="username">Username:</label>
<input type="text" id="username" name="username" />
When the user clicks on the "Username:" text it will focus the text box.
This is also good for accessibility as screen readers will read the label's inner HTML before reading the input field, regardless of the physical order they appear in the DOM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With