document.getElementClassName is not function

Hi Team,

In most of the apps, we have used document.getElementsByClassName to retrieve the HTML elements.

The app was working fine but from yesterday(approx) we started getting the below error for most of the apps (both custom and public).

Getting the below error from all the apps where we used the document.getElementByClassName.

We haven’t made changes to any apps.

Can we please check it?

App ID: 7656
FDK version: App’s latest changes pushed to the marketplace using Node 12 and FDK 7
Platform version 2.2

Let us know if you need more information.

Hi @kannansantharam,

The method, document.getElementByClassName returns HTMLCollection which is live. So, if an element selected by this array no longer qualifies for the selector, it will automatically be removed. There’s also a warning mentioned in MDN documentation for this method on this.

Also, forEach method is not available for this collection. Only length method is available. You would have to use Array.from method to convert results to an array and use forEach.

Maybe this situation didn’t occur before. It’s not related to our platform we believe.

Hi @Raviraj ,

We understood that we cannot use forEach for HTML Collections. Seems it was worked before so the developers used this method to build the app.

The concern is, we started getting this error from yesterday only.

For example, if we take the Jira Plus app, the latest version is live for a month and we haven’t received this error before. From yesterday only we are getting it.

Hi @kannansantharam

Thank you for providing a detailed summary of the issue.

We are not sure how it worked before. Based on the code, it should not. As you already know, this is a web API and not something our platform provides. This will mostly depend on the browser and the version. Was there a change of browser environment or the way the code is executed changed? Or maybe the error occured before but was not observed?

Just for reference here is a JSFiddle that works the same way.

I would recommend to update the code to adhere to the standards.

Let me know how I can help further.



This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.