Ensuring element exist when executed

Sometimes the element does not a exist the following with be thrown: Uncaught TypeError: Cannot call method 'off' of undefined