Please follow the below steps to achieve the required result
1. Take a variable name it maxdelcount assign the value 3 to it.
2. Take another variable delcount assign the value 0 to it.
3. Check the condition if delcount is less than maxdelcount before this line "$(this).remove()". if delcount is less than maxdelcount the remove the div and increment delcount.
4. If delcount is greater than or equal to maxdelcount then display the alert message.
Hope the above steps help
<script type="text/javascript">
var maxdelcount=2;
var delcount=0;
$(".form-horizontal").delegate("#removelink", "click", function () {
$(this).closest('.optiondiv').hide('slow', function(){
if (delcount < maxdelcount)
{
$(this).remove();
resequence();
delcount++;
}
else if (delcount >= maxdelcount)
{
alert("hi");
}
});
});
</script>