Refactor JS with data-attributes