• Resolved MNetto

    (@netto)


    Hello,
    in my results template simple JS is not working. I have a button that should trigger some action, but it doesn’t.

    
    $('.my-button').click(function() {
       console.log('hello');
    });

    I use a custom result template in my functions.php (with the sample code from here). Everything works, but not the JS.

    • This topic was modified 2 years, 11 months ago by MNetto.
    • This topic was modified 2 years, 11 months ago by MNetto.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takashi Matsuyama

    (@takashimatsuyama)

    Hello, @netto
    Thank you for your question.

    This Plugin outputs dynamic elements via Ajax.
    Therefore, perhaps it may be possible to write the following.

    
    $(document).on('click', '.my-button', function () {
       console.log('hello');
    });
    

    Or

    
    $(document).ajaxStop(function () {
        if ($("#ccc-my_favorite-list").find(".list-ccc_favorite").length > 0) {
            $(document).on('click', '.my-button', function () {
               console.log('hello');
            });
        }
    });
    

    And the above code assumes that it is written within the scope of jQuery.

    
    (function ($) {
     …
    })(jQuery);
    

    Thanks

    Thread Starter MNetto

    (@netto)

    Thank you very much! Now it works.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘js doesn’t work in result’ is closed to new replies.