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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:45:12+00:00 2026-06-18T08:45:12+00:00

Is it possible to lock a column based on it’s id using jquery? I’ve

  • 0

Is it possible to lock a column based on it’s id using jquery? I’ve seen different solutions, like header locking, and some can also lock the columns indexing from left. What I am trying to do is when I click the lock button, it will lock the column and won’t be moved when scrolled horizontally.

For example I click the lock on header 1, scrolled horizontally, then clicked lock on header 3. Header 1 and Header 3 should be adjacent to each other and shouldn’t move when scrolled horizontally.

Click here to view image

Below is my code:

<div style="float: left; width: 75%; overflow-x: scroll;">
<table style="width: 200% !important;">
    <tr>
        <td id="lid_1" colspan="3">
            <div style="margin-top: 3px;">
                January 24, 2013
                <button id="lid_1">Lock</button>
            </div>
        </td>
        <td id="lid_2" colspan="3">
            <div style="margin-top: 3px;">
                January 25, 2013
                <button id="lid_2">Lock</button>
            </div>
        </td>
        <td id="lid_3" colspan="3">
            <div style="margin-top: 3px;">
                January 26, 2013
                <button id="lid_3">Lock</button>
            </div>
        </td>
        <td id="lid_4" colspan="3">
            <div style="margin-top: 3px;">
                January 27, 2013
                <button id="lid_4">Lock</button>
            </div>
        </td>
        <td id="lid_5" colspan="3">
            <div style="margin-top: 3px;">
                January 27, 2013
                <button id="lid_5">Lock</button>
            </div>
        </td>
        <td id="lid_6" colspan="3">
            <div style="margin-top: 3px;">
                January 28, 2013
                <button id="lid_6">Lock</button>
            </div>
        </td>
    </tr>
    <tr>
        <td id="lid_1">Header 1</td>
        <td id="lid_1">Header 2</td>
        <td id="lid_1">Header 3</td>
        <td id="lid_2">Header 1</td>
        <td id="lid_2">Header 2</td>
        <td id="lid_2">Header 3</td>
        <td id="lid_3">Header 1</td>
        <td id="lid_3">Header 2</td>
        <td id="lid_3">Header 3</td>
        <td id="lid_4">Header 1</td>
        <td id="lid_4">Header 2</td>
        <td id="lid_4">Header 3</td>
        <td id="lid_5">Header 1</td>
        <td id="lid_5">Header 2</td>
        <td id="lid_5">Header 3</td>
        <td id="lid_6">Header 1</td>
        <td id="lid_6">Header 2</td>
        <td id="lid_6">Header 3</td>
    </tr>
    <tr>
        <td id="lid_1" colspan="3">
            <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                <tr>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                </tr>
                <br/>
            </table>
        </td>
        <td id="lid_2" colspan="3">
            <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                <tr>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                </tr>
                <br/>
            </table>
        </td>
        <td id="lid_3" colspan="3">
            <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                <tr>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                </tr>
                <br/>
            </table>
        </td>
        <td id="lid_4" colspan="3">
            <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                <tr>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                </tr>
                <br/>
            </table>
        </td>
        <td id="lid_5" colspan="3">
            <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                <tr>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                </tr>
                <br/>
            </table>
        </td>
        <td id="lid_6" colspan="3">
            <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                <tr>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                </tr>
                <br/>
            </table>
        </td>
    </tr>
</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-06-18T08:45:13+00:00Added an answer on June 18, 2026 at 8:45 am

    OK, here’s a solution to your update.
    However ids are meant to be unique so you shouldn’t have 2 or more same ids. Classes are the tool in general use-cases.
    You may add unique ids if unique columns are required but not using them as reference in the context of locking, but extract the id when you want to do something with it.

    Here are the examples:

    http://jsbin.com/odaxil/5

    http://jsbin.com/odaxil/5/edit

    js:

    (function (window, undefined) {
        jQuery(function () {
            bindings();
        });
    
        function bindings() {
            var locker = jQuery('#locker');
            jQuery(document).on('click', 'button.lockButton', function () {
                var that = $(this),
                    lidClass = '',
                    parent = that.parents('td[class^="lid"]');
                if (parent.length) {
                    lidClass = getColumnLidClass(parent);
                    lockings = jQuery('td.' + lidClass);
                    lockings.addClass('locked');
                    that.text('Unlock');
                    var fixedColumn = $(getLockedWrapper(lockings, lidClass));
                    var index = parent.index();
                    fixedColumn.data('index', index);
    
                    if (index === 0) {
                        locker.prepend(fixedColumn);
                    } else {
                        var lockedWraps = $('div.lockedWrap', locker),
                            lwrap = null,
                            indx, appended = false;
                        if (!lockedWraps.length) locker.append(fixedColumn);
                        lockedWraps.each(function () {
                            lwrap = $(this);
                            indx = lwrap.data('index') * 1;
                            if (!appended && (index < indx)) {
                                lwrap.before(fixedColumn);
                                appended = true;
                                return;
                            }
                        });
                        if (!appended) locker.append(fixedColumn);
                    }
                    that.text('Lock');
                } else {
                    parent = that.parents('div.lockedWrap');
                    lidClass = getColumnLidClass(parent);
                    lockings = jQuery('td.' + lidClass);
                    lockings.removeClass('locked');
                    parent.remove();
                }
            });
        }
    
    
        function getLockedWrapper(lockings, lidClass) {
            var fixedColumn = [],
                cont;
            lockings.each(function () {
                cont = $(this).html();
                fixedColumn.push('<div class="cellWrap">' + cont + '</div>');
            });
            fixedColumn = '<div class="' + lidClass + ' lockedWrap">' + fixedColumn.join('') + '</div>';
            return fixedColumn;
        }
    
        function getColumnLidClass(td) {
            for (var i = 0; i < 100; i++) {
                if (td.hasClass('lid_' + i)) break;
            }
            return 'lid_' + i;
        }
    })();
    

    HTML:

    <div id="locker"></div>
    <div style="float: left; width: 75%; overflow-x: scroll;">
        <table style="width: 200% !important;">
            <tr>
                <td class="lid_1" colspan="3">
                    <div style="margin-top: 3px;">January 24, 2013
                        <button class="lockButton" id="lid_1">Lock</button>
                    </div>
                </td>
                <td class="lid_2" colspan="3">
                    <div style="margin-top: 3px;">January 25, 2013
                        <button class="lockButton" id="lid_2">Lock</button>
                    </div>
                </td>
                <td class="lid_3" colspan="3">
                    <div style="margin-top: 3px;">January 26, 2013
                        <button class="lockButton" id="lid_3">Lock</button>
                    </div>
                </td>
                <td class="lid_4" colspan="3">
                    <div style="margin-top: 3px;">January 27, 2013
                        <button class="lockButton" id="lid_4">Lock</button>
                    </div>
                </td>
                <td class="lid_5" colspan="3">
                    <div style="margin-top: 3px;">January 27, 2013
                        <button class="lockButton" id="lid_5">Lock</button>
                    </div>
                </td>
                <td class="lid_6" colspan="3">
                    <div style="margin-top: 3px;">January 28, 2013
                        <button class="lockButton" id="lid_6">Lock</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="lid_1">Header 1</td>
                <td class="lid_1">Header 2</td>
                <td class="lid_1">Header 3</td>
                <td class="lid_2">Header 1</td>
                <td class="lid_2">Header 2</td>
                <td class="lid_2">Header 3</td>
                <td class="lid_3">Header 1</td>
                <td class="lid_3">Header 2</td>
                <td class="lid_3">Header 3</td>
                <td class="lid_4">Header 1</td>
                <td class="lid_4">Header 2</td>
                <td class="lid_4">Header 3</td>
                <td class="lid_5">Header 1</td>
                <td class="lid_5">Header 2</td>
                <td class="lid_5">Header 3</td>
                <td class="lid_6">Header 1</td>
                <td class="lid_6">Header 2</td>
                <td class="lid_6">Header 3</td>
            </tr>
            <tr>
                <td class="lid_1" colspan="3">
                    <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                        <tr>
                            <td>1</td>
                            <td>2</td>
                            <td>3</td>
                        </tr>
                        <br/>
                    </table>
                </td>
                <td class="lid_2" colspan="3">
                    <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                        <tr>
                            <td>1</td>
                            <td>2</td>
                            <td>3</td>
                        </tr>
                        <br/>
                    </table>
                </td>
                <td class="lid_3" colspan="3">
                    <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                        <tr>
                            <td>1</td>
                            <td>2</td>
                            <td>3</td>
                        </tr>
                        <br/>
                    </table>
                </td>
                <td class="lid_4" colspan="3">
                    <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                        <tr>
                            <td>1</td>
                            <td>2</td>
                            <td>3</td>
                        </tr>
                        <br/>
                    </table>
                </td>
                <td class="lid_5" colspan="3">
                    <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                        <tr>
                            <td>1</td>
                            <td>2</td>
                            <td>3</td>
                        </tr>
                        <br/>
                    </table>
                </td>
                <td class="lid_6" colspan="3">
                    <table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
                        <tr>
                            <td>1</td>
                            <td>2</td>
                            <td>3</td>
                        </tr>
                        <br/>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    

    CSS:

    .locked{
      display:none;
    }
    #locker{
      float: left;
      min-width: 100px;
      min-height: 110px;
      background-color: #333;
    }
    div.lockedWrap{
      float:left;
      margin-right:1px;
      background-color: orange;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I lock a file using java (if possible) I have
Possible Duplicate: How can I lock the first row and first column of a
Possible Duplicate: How can I detect if caps lock is toggled in Swing? How
Can someone explain, in detail, why it's possible to lock on objects of any
Is it possible to lock a particular range of cells based on the input
I'm wondering if it's possible to lock multiple mutexes at the same time, like:
Possible Duplicate: Device IMEI locking for tablets Is there any way to lock my
Is it possible to lock the aspect ratio of a JFrame in Java Swing?
Possible Duplicates: Why is lock(this) {...} bad? In C# it is common to use
Is it possible to track the accelerometer value while under the lock screen? 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.