I have two select dropdown with same classname, I will like to return the title when option value is selected. however with the code I have, when a second dropdown is changed, it still returns the value selected in first option dropdown
3 Answers
Because inside the change handler jQuery('.child_Select_Size option:selected') will select both the elements selected option and calling attr('title') on these matched elements will always give the title of the first element.
You should make use of this keyword which points to the element which raised the event. $(this).find will only look inside the element which raised the event. Also make use $ instead of jQuery if there is no conflict or use jQuery.noConflict()
$('.child_Select_Size').change(function(elmt){
alert($(this).find('option:selected').attr("title"));
});
Comments
You just need to use $(this) to refer to the select box that has changed, instead of just using a new selection (which will grab all).