added click event.
refactored common parts into the trigger function.