Why does my Phoenix instance not recognize JavaScript?

Phoenix 1.6

I wrote a simple dynamic javascript text change in assets/js/app.js

let dumb = document.getElementsByClassName("dumb")[0];
dumb.textContent = "SOME OTHER DUMB STUFF"

When I compile my app the above code is compiled in in. priv/static/assets/app.js

The code does not effect the text - but it is compiled to priv/static/assets/app.js

When my JS code is run outside of the phoenix app it works fine.

What am I doing wrong? I want to write dynamic JavaScript within my Phoenix App.

Thank you.

Related: What is the proper way to reference CSS libraries that have JS files in Phoenix?

Can you show the full file? Is this code being run at the appropriate time?

There is a good chance liveview is overwrting changes made to the dom by javascript…

Are You using liveview? Do You know about phx-update?

If You don’t see changes, perhaps You might debug with console.log()?

1 Like

I attached a screenshot.

The JavaScript file is being read, but the code is not active.

Screenshots below.

The class I am selecting is in lib/app_web/templates/layout/root.html.heex

I have tried applying the code to different templates and it does not affect the render.

EDIT:

When I go to sources in the browser developer tools there are no JavaScript files listed

I am not using liveview. The JavaScript file is being read but the code has a non-effect. The console has no errors. No missing file reads, errors or anything

EDIT:

When I go to sources in the developer tools there are no JavaScript files listed.

That is strange. I would check if the app.js is well referenced in the layout, otherwise I have no idea why…

I would compare your root layout to a new generated phoenix project. I think somehow the link to the assets got deleted.