theglasspenguin @theglasspenguin

so can html/javascript pros help me here with something (for something i’m working on)

i have a part of a webpage that i want to replace when a condition is met

i already have the if-statement, but when i use methods to replace the innerHTML, it doesn’t work

so uhh how do i replace a multiline html element with multiline html?

(sorry if this post is confusing)

Aug 10, 2022, 12:40 AM
11
View all Parent

comments

Highlighted comment

yes, i know. it’s not the if statement not checking multiple times, it’s not supposed to only check once at script startup, and i have verified that it works. it’s the fact that i can’t get the html element to update when i use (elementgoeshere).innerHTML = (stuffgoeshere)

Did you wait for the DOM content to finish loading? For context, the place where your script is placed is where the script will run, so if you put it at the beginning of a page it will have only loaded as much content as there was before the script.

All of my JavaScript is placed in a script.js file and I put the script load tags at the top of the page, just above the CSS load tags. I don’t think that’s the exact cause, it’s probably more of the code I’m trying to use, but I can’t test because I’m using an IDE.

You need to put the defer attribute on your script tag, otherwise you cannot put it in the head. For example: <script src=. . . defer>

It’s not in the head, it’s in the body, (in fact there is no head in the file yet)

just tested, it didn’t change anything, the code still doesn’t work

so it’s not the script placement, it’s the code itself that’s the issue

See more replies