refactored code and specs to include jQuery snippet