Title: Disable jQuery function on a particular page
Tags: jquery;wordpress
Question: I have a jQuery function which displays a lightbox pop-up:
function flatsomeQuickView(element) {
$(element).click(function(e){
$(this).after('<div class="ux-loading dark"&gt;</div&gt;');
var product_id = $(this).attr('data-prod');
var data = { action: 'ux_quickview', product: product_id};
$.post(ajaxURL.ajaxurl, data, function(response) {
$.magnificPopup.open({
removalDelay: 300,
items: {
src: '<div class="product-lightbox"&gt;'+response+'</div&gt;',
type: 'inline'
}
});
$('.ux-loading').remove();
$('.product-lightbox .product-gallery-slider').flickity({
cellAlign: "center",
wrapAround: true,
autoPlay: false,
prevNextButtons:true,
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) {
if(variation.image_src){
$('.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
$('.product-lightbox').addQty();
}, 600);
});
e.preventDefault();
}); // product lightbox
}
flatsomeQuickView('.quick-view');
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
<script&gt;
function flatsomeQuickView(element) {
$(element).click(false);
</script&gt;
add_action( 'wp_footer', 'quick_view_override', 100 );
but somehow .click() is not disabled for flatsomeQuickView function.

Here is the accepted answer: 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.
Comment for this answer: I have updated code to `$(element).off('click');` and my override code comes just under original function but still is not working (original function kicks in).
Comment for this answer: You don't need redefine `flatsomeQuickView` in your override code, it's kind of pointless in that case because you've already defined it and called it. You could've just called `$(element).off('click');`
Comment for this answer: Another very simple way of doing this would have been to use your `if $myvar == 'home'` logic to put a custom class on the `html` or `body` element, then in your original code just surround the original call to `flatsomeQuickView` with `if ($('.homepageClass').length){` ... `}`

Here is another answer: Got it to work based on RwwL answer but the final code is much more complex:
function quick_view_override() {
global $myvar;
if($myvar == 'home') {
echo <<<EOT
<script&gt;
function flatsomeQuickView(element) {
jQuery(element).off('click');
flatsomeQuickView('.quick-view');
jQuery('.woocommerce').arrive(".quick-view", function() {
flatsomeQuickView(jQuery(this));
});
</script&gt;
add_action( 'wp_footer', 'quick_view_override', 100 );

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:06/08/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<jquery><wordpress>', 'Title': 'Disable jQuery function on a particular page', 'ViewCount': 436, 'id': 37707021, 'user_AboutMe': '<p>Bedroom Coder, old school 8-bit fan</p>\n', 'user_AccountId': 1096964.0, 'user_DisplayName': 'JackTheKnife', 'user_Reputation': 3362.0, 'user_Views': 615.0, 'user_id': 1090360.0}}