recreate javascript functionality using jquery.