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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:34:47+00:00 2026-05-27T00:34:47+00:00

I have a table and I want to hide a column when I double

  • 0

I have a table and I want to hide a column when I double click a column.

Code for hiding a column is practically all around Stack Overflow. All I need is a hint on how/where to add the ondblclick event so I can retrieve the identity of a <td> within a <table>.

  • 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-27T00:34:48+00:00Added an answer on May 27, 2026 at 12:34 am

    Here are two solutions that should work. One done with jQuery and one with only standard Javascript.

    http://jsfiddle.net/GNFN2/2/

    // Iterate over each table, row and cell, and bind a click handler
    // to each one, keeping track of which column each table cell was in.
    var tables = document.getElementsByTagName('table');
    for (var i = 0; i < tables.length; i++) {
        var rows = tables[i].getElementsByTagName('tr');
        for (var j = 0; j < rows.length; j++) {
            var cells = rows[j].getElementsByTagName('td');
            for (var k = 0; k < cells.length; k++) {
                // Bind our handler, capturing the list of rows and colum.
                cells[k].ondblclick = column_hide_handler(rows, k);
            }
        }
    }
    
    // Get a click handler function, keeping track of all rows and
    // the column that this function should hide.
    function column_hide_handler(rows, col) {
        return function(e) {
            // When the handler is triggered, hide the given column
            // in each of the rows that were found previously.
            for (var i = 0; i < rows.length; i++) {
                var cells = rows[i].getElementsByTagName('td');
    
                if (cells[col]) {
                    cells[col].style.display = 'none';
                }
            }
        }
    }
    

    With jQuery it is much cleaner. This method also uses event bubbling, so you don’t need to bind an event handler to each table cell individually.

    http://jsfiddle.net/YCKZv/4/

    // Bind a general click handler to the table that will trigger
    // for all table cells that are clicked on.
    $('table').on('dblclick', 'td', function() {
        // Find the row that was clicked.
        var col = $(this).closest('tr').children('td').index(this);
        if (col !== -1) {
            // Go through each row of the table and hide the clicked column.
            $(this).closest('table').find('tr').each(function() {
                $(this).find('td').eq(col).hide(); 
            });
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some nested tables that I want to hide/show upon a click on
i have table with filmname and actors column in sql server 2005 i want
I have a repeater. And i want to hide and display a particular column
I have a problem with jquery and a dynamic table. I want a click
I have now some question about hiding some characters ... I want to hide
In my database I have a table called Price. I want to hide this
i have users table and i have posts table i want select from users
I have a table and I want to duplicate specific rows in the table.
I have a table where i want to change cell background on mouse over
I have a large table I want to include in a LaTeX document. It

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.