JackTheKnife JackTheKnife - 1 year ago 71
Javascript Question

Disable jQuery function on a particular page

I have a jQuery function which displays a lightbox pop-up:

function flatsomeQuickView(element) {
$(this).after('<div class="ux-loading dark"></div>');
var product_id = $(this).attr('data-prod');
var data = { action: 'ux_quickview', product: product_id};
$.post(ajaxURL.ajaxurl, data, function(response) {
removalDelay: 300,
items: {
src: '<div class="product-lightbox">'+response+'</div>',
type: 'inline'
$('.product-lightbox .product-gallery-slider').flickity({
cellAlign: "center",
wrapAround: true,
autoPlay: false,
percentPosition: true,
imagesLoaded: true,
lazyLoad: 1,
pageDots: false,
rightToLeft: false
setTimeout(function() {

// Run Variations Form Scripts
if ($('.product-lightbox form').hasClass('variations_form')) {
$('.product-lightbox form.variations_form').wc_variation_form();

$(".product-lightbox form.variations_form").on( "show_variation", function (event, variation) {
$('.product-lightbox .product-gallery-slider .slide.first img').attr('src',variation.image_src);
$('.product-lightbox .product-gallery-slider .slide.first a').attr('href',variation.image_link);
$('.product-lightbox .product-gallery-slider').flickity( 'select', 0);

// Create QTY Buttons

}, 600);

}); // product lightbox

which I don't want to execute on a home page (Wordpress site). For that I have created a WP action in the functions.php file

function quick_view_override() {

global $myvar;

if($myvar == 'home') {
echo <<<EOT
function flatsomeQuickView(element) {

add_action( 'wp_footer', 'quick_view_override', 100 );

but somehow
is not disabled for

Answer Source

jQuery's click (a shortcut for .on) does not take a boolean (see docs).

Use $(element).off('click'); if you're OK with disabling all click handlers on that element.