Reputation: 1
I have a function that check if CSS value exists, the problem is that I need the function to work only when the CSS class exists, currently the function running all the time because I'm using else condition (that need to re do the if condition).
//use for @media only screen and (max-width: 767px) detection
$(window).resize(function(){
if ($('#mobile-view').css('visibility') === 'hidden') {
$("#product-gallery").insertAfter("#product-info");
}
else {
$("#product-info").insertAfter("#product-gallery");
}
});
Upvotes: 0
Views: 2826
Reputation: 3591
you can use hasClass
if ($('#mobile-view').hasClass(className)) {
// put your logic inside this.
}
Upvotes: 0
Reputation: 173522
You could use the :hidden
pseudo selector:
if ($('#mobile-view').is(':hidden')) {
$("#product-gallery").insertAfter("#product-info");
} else {
$("#product-info").insertAfter("#product-gallery");
}
Upvotes: 3
Reputation: 11830
Change it to
if ($('#mobile-view').is(":visible")) {
$("#product-info").insertAfter("#product-gallery");
} else {
$("#product-gallery").insertAfter("#product-info");
}
Upvotes: 1