• Resolved amandathewebdev

    (@amandathewebdev)


    Hi all,

    I’m hoping someone can give me advice on this. I have a JavaScript function that used to work, and now it doesn’t. On this page: http://www.nfe-lifts.com/inventory/ when you check “Advanced Search”, a hidden div is supposed to show.

    Here is the function:

    $('#advanced-options').on('change', function() {
    
       $.cookie('advanced-search', $(this).is(':checked')?'1':'0');
    
       if($(this).is(':checked')) {
           $('#advanced-div').show();
       } else {
    
           $('#advanced-div').hide('slow');
    
       }
    
       if($.cookie('advanced-search') == '1') {
    
            $('#advanced-options').prop('checked', true).trigger('change');
    
       }
     });

    I’m on WP Engine and recently learned that they block certain cookies. They assured me that’s not what’s happening here. I’m not sure why this isn’t working. Any help would be appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I see this in my web console when I view your page: Error: Syntax error, unrecognized expression: a[href=#undefined]

    This causes scripts to stop working, so there isn’t any problem with what you posted, other than it no longer executes due to the error. A LOT of plugins and themes are getting this error after upgrading to WP v4.5. The code was wrong all along, but the latest version of jQuery shipped with 4.5 finally started enforcing proper syntax.

    The expression should be a[href="#undefined"]

    Thread Starter amandathewebdev

    (@amandathewebdev)

    Thanks for the reply. I see that error is occurring in the jquery that’s included in WordPress core, which I can’t touch. So how could I fix it?

    Or maybe it’s happening in this bit of code here, but when I update with double quotations, it doesn’t work:

    $('a[href=#'+fancybox_id+']').fancybox().trigger('click');
    
    	alert($('a[href=#'+fancybox_id+']').length)
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    It should be this:

    $('a[href="#' + fancybox_id + '"]').fancybox().trigger('click');

    Thread Starter amandathewebdev

    (@amandathewebdev)

    Andrew, that was it! Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘JavaScript/jQuery toggle not working’ is closed to new replies.