javascript - Jquery Chosen get the Id of un-selected value in dropdown -
i have manage id of selected option chosen plugin. here jsfiddle demo.
now not sure how id of unselected option. using code id of selected option.
var selectedids = $(this).find('option:selected').map(function() { if ($(this).attr('value') == params.selected) return $(this).prop('id') }).get(); alert(selectedids);
when option deselected, change event, params
object has deselected
property can use you're using selected
.
i made jsfiddle demonstrate: http://jsfiddle.net/1eut1c3d/
$("#chosen").chosen().on('change', function(evt, params) { if (params.selected !== undefined) { var selectedid = $(this).find('option:selected').map(function() { if ($(this).attr('value') == params.selected) return $(this).prop('id') }).get(); alert("selected: " + selectedid); } if (params.deselected !== undefined) { var deselectedid = $(this).find('option').not(':selected').map(function() { if ($(this).attr('value') == params.deselected) return $(this).prop('id') }).get(); alert("deselected: " + deselectedid); } });
Comments
Post a Comment