Link to home
Start Free TrialLog in
Avatar of radarhill
radarhill

asked on

jQuery Each - Value of Label for=""

I'm trying to retrieve the value of the for="" using jQuery's each.  I'm looking for the EventStartMonth and EventEndMonth values.  Am I on the right track or is there a better approach?  Thanks.
<script>
$(function(){
	$.each( $( '.input.datetime label[for$=Month]' ) , function( k , v ){
		alert( v.value );
	});
});
</script>
<div class="input datetime">
 <label for="EventStartMonth">Start</label>
	<select name="data[Event][start][month]" id="EventStartMonth"> 
	<option value="01">January</option> 
	<option value="02">February</option> 
	<option value="03">March</option> 
	</select>
 <label for="EventEndMonth">End</label>
	<select name="data[Event][end][month]" id="EventEndMonth"> 
	<option value="01">January</option> 
	<option value="02">February</option> 
	<option value="03">March</option> 
	</select>
</div>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of FrankoH
FrankoH

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Göran Andersson
You have got the label elements all right, but the label doesn't have the value so you have to find the select element inside the label:


$.each($('.input.datetime label[for$=Month] select') , function( k , v ){
  alert($(v).val());
});

or:

$.each($('.input.datetime label[for$=Month]') , function( k , v ){
  alert($(v).find('select').val());
});

Open in new window

Avatar of radarhill
radarhill

ASKER

Thanks.  Exactly what I was after.