I have two tables Table1 and Table2.
Each table contains tag and the options and their values were same.
Now I want to check for each table,
You are selecting all the options
instead of in the current table.
Live Demo
Change
$('option[value=' + $(this).val() + ']:selected')
To
$(this).closest('table').find('option[value='+$(this).val()+']:selected')
You can make single handler instead of multiple for each row and further simplify and optimize code like this.
$('select').change(function () {
if ($(this).closest('table').find('option[value=' + $(this).val() + ']:selected').length > 1)
{
alert('option is already selected');
$(this).val($(this).find("option:first").val());
}
});