user866933 user866933 - 1 year ago 55
jQuery Question

How to get id of select box after a known text inside label tag?

I have a div as shown below. I know there will be one text "User Type" within a label tag. There may be more than one text "User Type", but only one inside label tag. I need to get the id of tag select coming after this label. In this case it will be user_type_22. How i can get it using jquery?

<div class="form-group">

<label class="control-label" for="user_type_22">User Type</label>
<div class="control">
<select id="user_type_22" class="form-control" name="whateverbeit">


Answer Source

you can do it without a loop :

id = $("label:contains('User Type')").next('div').find('select').attr('id');