Closing when defined in a function
adam-jones-net opened this issue · comments
Adam Jones commented
Having a really simple problem. I'm trying to generate via a function and find that the close command doesn't work.
So I define global variable, then within the function try to update it whenever called.
var popup="";
function testPopup(content){
popup=basicLightbox.create(content+` - <span class="btnClose">CLOSE</span>`).show();
}
Then to catch the close button click...
$(document).ready(function() {
$(document).on('click','.btnClose', function(event){
popup.close();
});
});
When I click the close button I get popup.close is not a function msgs.
Tobias Reich commented
The show function isn't returning an instance. You can do it like this:
var popup="";
function testPopup(content){
popup=basicLightbox.create(content+` - <span class="btnClose">CLOSE</span>`);
popup.show();
}
Hope that helps :)
Adam Jones commented
Ah damm i thought it was something simple thanks! ;)