Monday, November 20, 2017

Getting the index of a table column by TH name

The Table HTML:
<table class="table table-bordered table-hover" id="table">
    <thead>
    <tr>
        <th class="text-center">Name</th>
        <th class="text-center">Phone number</th>
        <th class="text-center">Action</th>
        <th class="text-center">Message</th>
        <th class="text-center">Date</th>
        <th class="text-center">Actions</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>
Here's how to get the index of the "Date" column:
var idx = $('#table th:contains("Date")').index();

No comments:

Post a Comment