refactor tabs in pure javascript