Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shorthand jQuery to focus first input in form in div

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();
like image 647
Ben Avatar asked Dec 19 '22 16:12

Ben


1 Answers

Try something like this :

$('.detailEdit').find('input:first').focus();
like image 67
Nikola Loncar Avatar answered Dec 24 '22 03:12

Nikola Loncar