refactor jQuery solution