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 8291653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:12:22+00:00 2026-06-08T13:12:22+00:00

I have the following: var oTable = $(‘#dataTable’).dataTable({ iDisplayLength: -1, … … $(#dataTable tbody).on(click,

  • 0

I have the following:

var oTable = $('#dataTable').dataTable({
    iDisplayLength: -1,
    ...
    ...

$("#dataTable tbody").on("click", "tr", gridClickHandler);

function gridClickHandler(oTable) {
    $(oTable.fnSettings().aoData).each(function () {
        $(this.nTr).removeClass('row_selected');
    });
    $(this).addClass('row_selected');

I was told that the $(this) event will be passed to the function but I need to also pass something else as I found it gives an error relating to oTable.

How can I modify my call to gridClickHandler and the gridClickHandler function so it passes a reference to oTable and also so the $(this) works.

  • 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-06-08T13:12:24+00:00Added an answer on June 8, 2026 at 1:12 pm

    If the variable oTable is declared in an outer scope, the gridClickHandler function will have access to it, so you don’t need to pass it manually. As a matter of fact, event handlers receive the event object as the first argument, so you’re actually shadowing the TABLE reference.

    For example:

    var foo = 123;
    
    var clickHandler = function ( foo ) {    
        // here, foo is not 123, but the event object  
        // the outer variable foo is shadowed by the local variable foo  
    };
    

    Just remove the first argument:

    var gridClickHandler = function () {
    

    Now, oTable is retrieved from the outer scope.

    (Also notice, how I assign a anonymous function expression to a variable, instead of using a function declaration.)

    Btw, inside the function, this refers to the TR element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery code: $(#dataTable tbody) .on(click, tr, function (event) { $(oTable.fnSettings().aoData).each(function
I have the following datatable: $(function() { var dataTableColumns = [ { sType: numeric
I have the following: var X = $('p:first'); $(X).each(function(index,Element) { tbody = ''; tr
I have the following: var Save = $('th:first')[0]; $('th').click(function() { if (Save !== this)
I have the following: var parsed_contacts = jQuery.parseJSON(conts); $('#contacts > li > a').click(function(event){ target_id
I have the following: var thiscode = { init: function(){ jQuery('#submit').bind('click',thiscode.clickListener); }, clickListener: function(event){
I have the following jQuery: $('#dataTable').on('click', 'tbody tr', clickHandler); Here's the first few lines
I have the following: var doHandler = function (link, form, close) { var $form
I have the following code: var submitHandler = function ($link, $form, close) { var
Greetings, I have the following JS code: var reloadTimer = function (options) { var

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.