on click event added inside if statement