2

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.

4

4 回答 4

8

使用非常具体的选择器:

var textboxId = $('div.FH_element.FH_text.required')
    .find('input[type="text"]')[0]
    .id;
于 2012-05-18T21:56:14.757 回答
5
jQuery('.required input').attr('id')
于 2012-05-18T21:55:54.833 回答
4

这应该有帮助

var textBoxId = $('.required').find('input[type=text]').attr('id');
于 2012-05-18T23:48:09.190 回答
3

尝试这个:

$('.required').find('input').attr('id')
于 2012-05-18T21:57:09.033 回答