I won't call it a solution, but a work around.
I just changed the position of javascript and it started working fine. Scripts were present at the top inside document.ready and elements at bottom that created and created the issue as some dynamic elements get created on runtime which messed up the functionality. now when I brought all my scripts to the bottom of the page everything got set
.