Currently, I am utilizing the .on()
method with jQuery to display a specific div, and also using .load()
to fetch a particular div from a web page hosted on my server.
My query is how can I close this div when clicking outside of it, along with removing it from the DOM to prevent multiple reloads?
This div is part of the footer section and it can be toggled by clicking a link in the footer.
I attempted using .off() in the following way:
if ($(window).width() > 500) {
//
$('.marketSelector',this.$element).on('click', function(e){
e.preventDefault();
var testMarketSelector = $('.testMarketSelector');
testMarketSelector.css({
'display': 'block'
});
testMarketSelector.load( "/frontend/MarketSelector.html .MarketSelector" );
testMarketSelector.off("click", function(){
testMarketSelector.css({
'display': 'none'
});
});
});
}
I also experimented with .one():
if ($(window).width() > 500) {
//
$('.marketSelector',this.$element).one('click', function(e){
e.preventDefault();
var testMarketSelector = $('.testMarketSelector');
testMarketSelector.css({
'display': 'block'
});
testMarketSelector.load( "/frontend/MarketSelector.html .MarketSelector" );
});
}