I have two models one for desktop view and the second for mobile view. I want that on mobile view only mobile modal should display and not the other and same with the desktop view. This is my javascript code for this.
var width = $(window).width();
$(window).on('resize', function() {
if ($(this).width() !== width) {
width = $(this).width();
}
});
var myBtn=$('.myBtn');
var modal1= $('.modal1');
var mobilemodal1=$('.mobilemodal1');
setInterval(function(){
console.log(width);
if(width>768)
{
myBtn.click(function(){
modal1.css("display","block");
});
}
else{
myBtn.click(function(){
mobilemodal1.css("display","block");
});
}
},1000)
Here modal1 is my desktop modal and the mobile modal is for mobile view. myBtn is the class given to both the modals to trigger them when clicked. The problem is when I am on mobile screen size I click the button I get only mobile modal but then I stretch the screen size to desktop view then when I click the button I get both the modals. The same is the case when I start with the desktop screen. I do not know the reason for this peculiar behavior. Please help I have searched a lot over the internet. When I had no choice I came here. Please help.