All threads / Chrome Only - getElementsByClassName error
Ask A Question


You’re not receiving notifications from this thread.

Chrome Only - getElementsByClassName error

Mountaindog asked in Javascript

I am hoping someone might be able to shed some light on this issue. I have this JS code (below) located in packs -> application.js. It grabs the class name and adds additional class. The division's names are temp placeholders. When running in development mode, it works great in all browsers (Chrome, FF, Safari). When tested in a production environment, it works only in FF and Safari. Not in Chrome. Hmmm.... I’ve tried moving the code out of Webpacker (application.js) and received the same results.

The only error Chrome gives is: Uncaught TypeError: Cannot read properties of null (reading 'classList')

I’m certainly open to suggestions, ideas, improvements.

window.addEventListener("load", function (event) {
var divisions = ['one', 'two', 'three', 'four', 'five', 'six']
divisions.forEach(function (item) {
var director_office = document.getElementById(item).getElementsByClassName('google-visualization-orgchart-table')

Ruby: 2.7.3

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 70,078+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.