Fixing spacing, using better selectors and applying the event.preventdefault at the starting of the function