WordPress.org

Forums

WP Ajaxify Comments
[resolved] Other jQuery Code not working after comment is posted (4 posts)

  1. adriansr
    Member
    Posted 1 year ago #

    Hi! Your plugin is amazing. I really want to use your plugin, but I'm having a problem with other jQuery code. Please help.

    At the bottom of the page, I made a simple button for scrolling back to the top of the page.
    After loading the page, my button works fine.
    However, after posting a new comment, my button would no longer work. I can click the button but the page won't scroll anymore.
    The comment is successfully posted and the commenting system continues to work well, but my button becomes non-functional.

    At the bottom of the page, i have this markup:
    <input id="asr-bottom-button-to-page-top" type="submit" value="Go to Top">

    In my custom js file, I have this code:

    jQuery(document).ready(function(){
         jQuery("#asr-bottom-button-to-page-top").click(function(){
              jQuery('html, body').animate({scrollTop:0});
         });
    });

    In my child theme's functions.php file, I have this code:

    if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
    function my_jquery_enqueue() {
    	wp_enqueue_script( 'pcritic', get_stylesheet_directory_uri() . '/js/pcritic.js' );
    }

    ==========
    https://wordpress.org/plugins/wp-ajaxify-comments/

  2. janjonas
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,
    thanks for your comment. If the asr-bottom-button-to-page-top button is replaced when posting a comment, i.e. the button is contained in the comments container your jQuery code no longer works since the domready event is not fired again and the button click event is not initialized.

    Please try to change your code in the custom js to

    jQuery(document).ready(function(){
         jQuery("#asr-bottom-button-to-page-top").on("click", function(){
              jQuery('html, body').animate({scrollTop:0});
         });
    });

    Please note: This code requires jQuery >= 1.7 which should not be a problem.

    If this does not work please send me a link to your page and a will examine the problem in more detail.

    Hope this helps...
    Jan

  3. adriansr
    Member
    Posted 11 months ago #

    Thanks Janjonas. Problem already solved. I used the .on() for JQuery, but bound it to the parent div, to catch the bubbling of the event from within the comments container. Thanks :-)

  4. janjonas
    Member
    Plugin Author

    Posted 11 months ago #

    Thanks for your feedback.
    Maybe you can think about switching your review from 4 stars back to 5 stars :)...

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Ajaxify Comments
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic