jQuery(".quickButtonsElement").click(function (e) { let isHandy = window.matchMedia("only screen and (max-width: 500px)").matches; let isMediumTablet = window.matchMedia("only screen and (max-width: 1151px)").matches; let buttonPosition = jQuery(this).position().left + jQuery(this).width();
if (isHandy) { // we're on mobile if(buttonPosition <= 0.50 * 270) { // the button is opened // do the action } else { // the button is closed // open it up but don't do any action yet e.preventDefault(); return false; } } else if(isMediumTablet) { // we're on mobile if(buttonPosition <= 0.50 * 270) { // the button is opened // do the action } else { // the button is closed // open it up but don't do any action yet e.preventDefault(); return false; } } });