I've got a table I'm working on that's populated on the backend by a DB. I've found a nice script to sort the data as it's displayed on the page, and I'm trying to add/remove classes to indicate:
- which column is being sorted
- Ascending or decending order
To do the sorting, I'm using document.querySelectorAll
to attach an event listener to each of the table's th
. Since I already have the event listener in place, I though that I could use an if statement with classList
to add or remove my classes as needed. However, I keep running into an Uncaught TypeError: Cannot read property 'contains' of undefined. Here's my fiddle
I'm trying to do this witout relying on jQuery, because the library attached to this particular code is woafully outdated. Updating to something modern would break a lot of existing functions that otherwise work well.
Unfortunately, i know jQuery much better than Vanilla JS. Not sure what I'm missing here. Any direction would be helpful.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment