Search code examples
jqueryclasshtml-tablehead

Finding specific table head using jQuery


Is there a method in jQuery to count across multiple table head classes ( <th class="entity7">Machine Names</th> tag) until a table head with the value "Machine Names" is found? "Machine Names" is the value in the particular table head cell I need to count to. This will allow me to know which number column I want to work with.


Solution

  • You can use filter() for this:

    var $th = $("#myTable th").filter(function() {
        return $(this).text() == "Machine Names";
    });
    var columnNumber = $th.index();