Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7161565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:35:17+00:00 2026-05-28T13:35:17+00:00

I have a dataTable that uses pagination. Now when my page loads then my

  • 0

I have a dataTable that uses pagination. Now when my page loads then my jQuery run. which hides the answers in TD, then if you click on TD or move your mouse to TD the my other jQuery code runs. Here is the code

(function($){

    var hideAnswers = function() {

        $('#faqGrid tr td').each(function(){

            var $td = $(this);
            $td.children('div .answer').hide();

        }); //end of $('#faqGrid tr td').each(fn)

    }; //end of var hideAnswers = function() {}

    hideAnswers();

    /**
     * .delegate( selector, eventType, handler(eventObject) )
     *
     * selector: A selector to filter the elements that trigger the event.
     * eventType: A string containing one or more space-separated JavaScript event types, such as
     * "click" or "keydown," or custom event names.
     *
     * handler(eventObject): A function to execute at the time the event is triggered.
     *
     * Description: Attach a handler to one or more events for all elements that match the selector,
     *  now or in the future, based on a specific set of root elements.
     */

    $("#faqGrid").delegate("td", "click", function() {

        var $td = $(this);

        $td.children('div .answer').animate({

           opacity: 'toggle',
           height: 'toggle'

        }, 'slow');

    }); //end of $("#faqGrid").delegate("td", "click", fn());

     /**
      * mouseenter and mouseleave only triggered when the mouse first enters the <div> and
      * finally leaves it. IF you consistently want the mouse event in a div, then use mouseover(fn)
      */
     $('#faqGrid').delegate('td div.question', 'mouseenter', function(event){

         // current div
         var $div = $(this);

         //Find current div parent which is td. So we can check for answer div for this td.
         //Only travels a single level up the DOM tree.
         var $td = $div.parent();

         $td.addClass('hover');

         // create tooltip div
         var $tooltipDiv = $('<div class="tooltip"></div>');

         // find current div class attributr value
         var divClass = $div.attr('class');

         if (divClass == 'question'){

             // Find <div class=answer /> for this td
             var $answerDiv = $td.find('div.answer');

             // If answer div is hidden then only show the tooltip
             if ($answerDiv.is(':hidden')) {

                 /**
                  * This line will create something like this.
                  *
                  *     '<div class="tooltip">click to see the answer</div>'
                  *
                  * Then when mouse leave, we will get this text using .html() and set it to
                  * to span title attribute value. So when next time mouse enter then we have the
                  * title text.
                  *
                  * $(this).find('span').attr('title',$('.tooltip').html());
                  */
                 $tooltipDiv.text("Click to see the answer").appendTo('body');

                 //change tooltip position
                 var tooltipX = event.pageX - 8;
             var tooltipY = event.pageY + 8;
             $('div.tooltip').css({
                                    top: tooltipY,
                                    left: tooltipX
                                     }
                                  ); //end of .css

                 //hide the tooltip with fadeOut effect in 3 sec
                 $('div.tooltip').fadeOut(3000);

                 //$(this).find('span').attr('title',$('.tooltip').html());

             } else { //end of if ($answerDiv.is(':hidden'))

             }

         } //end of if ($div.attr('class') == 'question'..)

     }).mousemove(function(event){

         //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
        var tooltipX = event.pageX - 8;
    var tooltipY = event.pageY + 8;

        $('div.tooltip').css({
                              top: tooltipY,
                              left: tooltipX
                             }
                        ); //end of .css

    }).mouseleave(function() {

        //Put back the title attribute's value
        //$(this).find('span').attr('title',$('.tooltip').html());

        //Remove the appended tooltip template
        $(this).parent().removeClass('hover');

        $('div.tooltip').remove();

    });

})(jQuery); //end of (function($)

You people can see i am delegating my two events. I know the type of the event, like click and mouseenter. But i want to ask what should be the event type when we want to run function when page loads or when we do pagination?

My hideAnswers() method only runs when page loads. If i do pagination then due to ajax request current DOM Html changes and my hideAnswers() method don’t run. So how can i delegate my hideAnswers()method also?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:35:18+00:00Added an answer on May 28, 2026 at 1:35 pm

    Well your code responsible for pagination should be able to provide you with some callback method called once new page is loaded and inserted into DOM. So you could call your hideAnswers from this callback. In your case it’s not possible because you defined this function inside a closure. So then you could trigger some custom event. You would listen for this event:

    $("#faqGrid").delegate('td', 'hideAnswers', hideAnswers);
    

    And inside your pagination callback you would trigger this event as follows:

    $("#faqGrid").trigger('hideAnswers');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView that is bound to a DataTable, which in turn uses
I have a Linq query that returns an anonymous type, which I then use
I have a datatable that uses the cell editor function. In each row, I
I have an application that uses DataTables to perform grouping, filtering and aggregation of
I have a DataTable that queries out something like below usergroupid...userid......username 1.............1...........John 1.............2...........Lisa 2.............3...........Nathan
I have a DataTable that has a boolean column called [Invalid]. I need to
I have a datatable that has a date column, but I am stumped as
I have a DataTable that I manually created and loaded with data using C#.
I have a datatable that contains rows of transaction data for multiple users. Each
Ok. So I am pretty new a this. I have a datatable that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.