fix index bug when element switch