user1390436
user1390436

Reputation: 61

Get a textbox id inside a div in jquery

I need your help to find textbox id inside a div based on div's css class name in jquery.

<div class="FH_element FH_text required" id="FH_0_first_name">
    <label for="FHE_0_first_name">First*<small></small></label>
    <div>
        <input type="text" title="" name="first_name" value="" tabindex="3" id="FHE_0_first_name">
    </div>
</div>

In the above code i need to find the textbox id(FHE_0_first_name) using div's class name(required)..in jquery.

Upvotes: 2

Views: 19073

Answers (4)

Kumar
Kumar

Reputation: 95

This should help

var textBoxId = $('.required').find('input[type=text]').attr('id');

Upvotes: 4

yankee
yankee

Reputation: 40810

jQuery('.required input').attr('id')

Upvotes: 5

ampersandre
ampersandre

Reputation: 3216

Try this:

$('.required').find('input').attr('id')

Upvotes: 3

Matt Ball
Matt Ball

Reputation: 359876

Using very specific selectors:

var textboxId = $('div.FH_element.FH_text.required')
    .find('input[type="text"]')[0]
    .id;

Upvotes: 8

Related Questions