Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click on <div> to focus <input>

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?

like image 962
Erik Avatar asked Apr 15 '12 16:04

Erik


People also ask

Can we set focus on Div?

Yes - this is possible. In order to do it, you need to assign a tabindex...

Does click trigger focus?

Triggering a click synthetically does not cause focus to switch to the element, however the click triggered by hardware does.

How do I add focus to click?

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.


1 Answers

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" /> 
like image 85
apnerve Avatar answered Oct 03 '22 07:10

apnerve