Here is the solution in detail. This aims to keep the original code as intact as possible, so that the same code can be easily used and maintained across all web browsers.
Getting started
First, is for me to install IE8, because using other IE’s emulations isn’t as accurate as using the real thing ™.
Even though IE8 doesn’t work on Windows 10, Microsoft gives away virtual machines with it on there.
https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/
And to make the code easily accessible, I can just run live-server from my main machine, and access it from my virtual machine on 192.168.1.138:8080
Getting IE8 to run anything of the code
Using Babel to convert the existing JavaScript code into ES5 lets the code be used both by IE8 and anything more recent, because let statements are turned into var statements, and arrow-notation is turned into normal functions.
With that in place, IE8 loads the page, and gives us the first of many errors that will be resolved.
I can use the F12 developer tools screen to help find out the problem, by going to the Script tab and selecting the console to find out details about what’s causing the problem.
IE8 event handler
Unable to get property ‘parentElement’ of undefined or null reference
var table = e.target.parentElement.parentElement.parentElement.parentElement;
The parentElement issue occurs because IE8 doesn’t have a target object in the event object.
While it’s possible to polyfill almost every IE8 issue, I don’t think that there’s one that fixes how IE8 responds to events. We can though use a minimal technique where we try to get e.target first, and if that fails we then attempt to get e.srcElement instead.
// var table = e.target.parentElement.parentElement.parentElement.parentElement;
var el = e.target || e.srcElement;
var table = el.parentElement.parentElement.parentElement.parentElement;
We can now use one of the text entry fields, to find out other IE8 problems.
Array.from polyfill
Object doesn’t support this property or method
var searchText = Array.from(fields).map(function (field) {
We can now use some polyfills to patch up problems that IE8 has. A nice an easy way of doing this is from polyfill.io where we can just select the ones that we require, and they’re packaged together for us.
First I select to Minify the code, and to use Feature detects.
Then I can use the search field to search for from, and select Array.from in the list.
Finally I select the HTML bundle tab and copy that code.
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?flags=gated&features=default%2CArray.from"></script>
With that in place before the scripting code, IE8 gives us the same error but it’s all okay, because it’s for a different problem.
String.trim polyfill
Object doesn’t support this property or method
return field.value.trim();
We now need to include a polyfill for trim, so I can search the polyfill site for trim, select that and copy the HTML bundle code.
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?flags=gated&features=default%2CArray.from%2CString.prototype.trim"></script>
Replacing the old bundle for that one, IE8 now gives a new error. That’s good, it means that we’re making progress.
Element.classList polyfill
‘classList’ is null or not an object
row.classList.toggle('hidden-row', hideRow);
IE8 now needs to be told how to use classList, so another polyfill is needed.
Search the polyfill builder page for class, select Element.prototype.classList, and copy the HTML bundle code.
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?flags=gated&features=default%2CArray.from%2CString.prototype.trim"></script>
Use that instead of the previous one, and the code now looks to fully work on IE8.
Summary
The above is a fairly easy process to fairly easily get code working on IE8 using a trial-and-error approach, fixing problems as and when they occur when IE8 is running the code.