According to my research and testing , when we open the HTML file in the SharePoint Library, only the part of the HTML can be displayed, and JavaScript does not work, unfortunately, it is by default. As a workaround, you can input your code in Script Editor web part, and the JavaScript will working in the web part. You can follow these steps:
1.Go to Page ->>Click "New" ->> Click "Wiki Page"
2.Click "INSERT" ->> Web Part ->> Media and Content ->> Script Editor ->>Click "Add"
3.Click "Edit Web Part"
4.Click "EDIT SNIPPET"
5.Input your code and Click "Insert" ->> Click "OK" ->>Save the page
My test result (In my test, JavaScript works well) :
Hope it can help you. Thanks for your understanding.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.