Why in the console writes:
Uncaught TypeError: commercialOfferModal.close is not a function
Why is self or commercialOfferModal undefined in this code?
If commercialOfferModal.close(); call the commercialOfferModal function from the outside, then everything works, but not from the inside. Because commercialOfferModal is undefined ?
(function commercialOfferModal(){ var self = this; $('.commercial-offer-modal_open').click(function(){ $('.commercial-offer-modal__overlay').fadeIn(300); $('.commercial-offer-modal__content').animate({'right': "0"}, 300); }); $('.commercial-offer-modal_close').click(function(){ self.close(); }); $('.commercial-offer-modal__overlay').click(function(){ self.close(); }); })(); commercialOfferModal.close = function(){ $('.commercial-offer-modal__overlay').fadeOut(200); $('.commercial-offer-modal__content').animate({'right': "-704px"}, 300); $('input').removeClass('error'); $('p.error-text ').text(''); };