<select id="sel">
<option id="1">aa</option>
<option id="2">bb</option>
<option id="3">cc</option>
</select>
<select id="two">
<option id="1">aa</option>
<option id="2">bb</option>
<option id="3">cc</option>
</select>
function showalert(){
alert($(this).find('option:selected').attr('id'));
}
$("#sel").change(function(){
showalert();
});
$("#two").change(function(){
showalert();
});
How to correctly use $(this) in these function? Now this is undefined.
pass
$(this)to the function.Edited from the comments.
The comments are suggesting that you do not pass a jQuery object and infact it makes sense as it is just extra code and should be refactored into the method.