I have a series of input
elements each with a few <div>
tags separate.
I like to have if where I can click
on any of the <div>
and it will focus
on an input
.
Is this possible and if so can anyone give ideas on script?
Yes - this is possible. In order to do it, you need to assign a tabindex...
Triggering a click synthetically does not cause focus to switch to the element, however the click triggered by hardware does.
To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.
I don't see a reason why you need JS
to do this when such feature is already provided in HTML
.
<label for="YOURID">The clickable region<label> <input id="YOURID" type="text" />
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