Refactor the code without Jquery lib