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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:16:14+00:00 2026-06-08T20:16:14+00:00

I folks, I have following javascript function, which should check for the index of

  • 0

I folks, I have following javascript function, which should check for the index of a column in a table. The problem is the comparison of the columnName and the name from the table.
I have tested with columnName ‘ID’ and this column is found in the table, but the comparison is not true, so that the index is not returned.

My code:

function getColumnIndex(columnName, grid) {
    console.log("loading column index for column: [" + columnName + "]");
    $('div.hDivBox > table > thead > tr > th', grid).each(function(index) {
         var name = $(this).attr('title');
         console.log("Checking cell: [" + name + "]");
         if (String(name) == columnName) {
              return index;
         }
    });
    console.log("no cell found with name: " + columnName);
    return -1;
} 

The log statements:

loading column index for column: [ID]
Checking cell: [ID]
Checking cell: [Name]
Checking cell: [Description]
Checking cell: [AddTime]
Checking cell: [UpdTime]
no cell found with name: ID

An example of the HTML, which is analyzed by the javascript function:

<div class="hDivBox">
<table cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th align="center" hidden="" axis="col0" title="ID" style="display: none;">
                <div style="text-align: center; width: 30px;">ID</div>
            </th>
            <th align="center" axis="col1" title="Name" class="">
                <div style="text-align: center; width: 250px;">Name</div>
            </th>
            <th align="center" axis="col2" title="Description" class="">
                <div style="text-align: center; width: 250px;">Beschreibung</div>
            </th>
            <th align="center" axis="col3" title="AddTime">
                <div style="text-align: center; width: 120px;">hinzugefügt</div>
            </th>
            <th align="center" axis="col4" title="UpdTime">
                <div style="text-align: center; width: 120px;">aktualisiert</div>
            </th>
        </tr>
    </thead>
</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-08T20:16:17+00:00Added an answer on June 8, 2026 at 8:16 pm

    Just use a jQuery attribute selector to match the title and use index() instead of looping yourself.

    function getIndexByTitle( title ) {
     return $('th[title="' + title + '"]').index();
    }
    
    alert(getIndexByTitle("ID"));
    alert(getIndexByTitle("Name"));
    

    Example

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

Sidebar

Related Questions

Folks, we have the following problem: we've got several objects containing table data that
Folks, I have a problem. I am a writing a script in python which
Folks, i have the following problem. My website uses an iframe to select an
Hej folks, I'm currently completely stuck with the following and don't even have the
Hello folks :) I have a quick question - For the following NSMutableArray: NSMutableArray
Folks, I have ASP.NET MVC 3 Application and I have the following JQuery script
I have the following scenario: 1) A phone book table 2) Multiple ways of
Hi folks I have the following error on line 11 in this controller code
I have the following situation and I'm expecting some expert advise from SO folks.
Folks, Let's say that I have the following situation: <div class=outer> <div> <span> <ul>

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.