What I'm trying to do
On the user click, I wish to focus on the first input
in the (only) form inside the child div
with the class detailEdit
.
The jQuery code I have works - but it seems like a fairly long way round. Is there a shorthand version?
My Code
HTML/PHP
<div class="detailEdit">
<form id="frm_contact">
<span>Office:</span><br/>
<input type="text" placeholder="Company Telephone" id="frm_tel2" name="tel2" maxlength="11" value="<?php echo $userData['tel1']; ?>" />
<span>Mobile:</span><br/>
<input type="text" placeholder="Mobile Number" id="frm_tel1" name="tel1" maxlength="11" value="<?php echo $userData['tel2']; ?>" />
<input type="submit" value="Submit" name="submit" />
</form>
</div>
jQuery
$(this).children('div.detailEdit').first().children('form').first().children('input').first().focus();
Try something like this :
$('.detailEdit').find('input:first').focus();
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