Created by: chi-lee
JQuery's index() function is not working sometimes. Using prevAll() instead avoids the problem.