Click on <div> to focus <input>
71,391
Solution 1
Try this with jquery:
$('#yourdiv').click(function() {
$('#yourfield').focus();
});
Solution 2
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" />
Solution 3
Try this :
<input id="myInput" />
<div onclick="document.getElementById('myInput').focus(); return false;"></div>
Solution 4
$('div').click(function() {
$(this).find('input[type="text"]').focus();
});
Solution 5
- using javascript (call .focus() on the input element)
- using wrapped around your div (makes only sense if the div is the label)
Author by
Erik
Christian, Father, Husband, Servant, Runner, SoCal Native, and forgiven, acting on my Faith in Jesus Christ as a new creation on good soil.
Updated on October 02, 2020Comments
-
Erik over 3 years
I have a series of
input
elements each with a few<div>
tags separate.
I like to have if where I canclick
on any of the<div>
and it willfocus
on aninput
.
Is this possible and if so can anyone give ideas on script?