How to add active class dynamically

You should change $i == 1 to $i++ == 1

tech