added on click event inside of an if statement