The issue i am facing is that I have a table with 5 <td>. The default color of <td> is red, and it changes its color to blue if user click on it first time, and changes to orange if user click on it second time, and third time it changes its color back to red and it goes on.
What I want is that if any of <td> has blue or orange color, and user click on any other <td> to change it colors, it should alert him "Not allowed, please un-select your previous ", then the user clicks on the selected <td> to change its color back to red and then select any other he wants.
here is my code sample:
$(".OpnSeat").on('click', function(e) {
if ($(this).attr("class") == "OpnSeat seat_td") {
$(this).addClass('openM seat_td');
} else if ($(this).attr("class") == "OpnSeat seat_td openM") {
$(this).removeClass('openM seat_td');
$(this).addClass('openF seat_td');
} else if ($(this).attr("class") == "OpnSeat openF seat_td") {
$(this).removeClass('openM seat_td openM');
$(this).removeClass('openF seat_td openM');
$(this).addClass('OpnSeat seat_td');
}
});
.seat_td {
width: 60px;
margin-right: 10px
}
.OpnSeat {
color: red;
border: 2px solid red;
}
.openM {
color: blue;
border: 2px solid blue;
}
.openF {
color: orange;
border: 2px solid orange;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="OpnSeat seat_td">
<p class="intxt">1</p>
</td>
<td class="OpnSeat seat_td">
<p class="intxt">2</p>
</td>
<td class="OpnSeat seat_td">
<p class="intxt">3</p>
</td>
<td class="OpnSeat seat_td">
<p class="intxt">4</p>
</td>
<td class="OpnSeat seat_td">
<p class="intxt">5</p>
</td>
</tr>
</table>
AND HERE IS THE WORKING JSFIDDLE
I am not good in English, I hope i conveyed my issue, any idea or hint in this would be highly appreciated.