Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running against a class results in "Element must be a table" error #214

Open
adam-jones-net opened this issue Sep 17, 2021 · 1 comment
Open
Labels

Comments

@adam-jones-net
Copy link

I am initialising the plugin with

new Tablesort(document.getElementsByClassName('trackTable'), {
    descending: true
});

on a table that starts:

<table id="mySearchesTable" class="trackTable noSelect" cellpadding="0" cellspacing="0">

Yet I get the following error:

Uncaught Error: Element must be a table

@tripu tripu added the invalid label Sep 19, 2021
@tripu
Copy link
Collaborator

tripu commented Sep 19, 2021

Document.getElementById(), which is the usual way of picking the table element, returns a scalar (an Element), while Document.getElementsByClassName() returns a vector (an HTMLCollection).

If you're sure you have just one element with that class, try something like:

document.getElementsByClassName('trackTable')[0]

But it's much better if you pick the element by its ID!

(Please confirm that's the issue you're having, so I can close this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants