Ultimately I’m trying to set my H1 text to the name of the current page, using this script in an HTML embed element or in the Project Settings custom code section:
document.getElementById(“pagename”).textContent = location.pathname.split(“/”).slice(-1); //haven’t tried this part yet
But firstly I can’t get this to work using an HTML Embed element:
Always share your read-only project link. If we can’t see your project, very little we can do to help.
That said, my first guess would be is that in the designer you’ve set your ID with different casing like PageName or Pagename. ID’s are case-sensitive, so they need to match exactly what you’re referencing in your script.
True I should have done that. Thanks for helping. Should the text load in the designer or do i need to publish and view live? It seems it would as I’ve linked images before in the embed element and it loaded in the designer.
I think this is it- you have the script running before the element exists.
In an inline script like this, it can only access DOM elements that have already been created.
You should be able to fix it by editing your nav symbol and then move the HTML Embed to the bottom of your nav, after #newpagename
Thanks, I’ll check it out.
One more thing if you don’t mind, moving the element to the bottom removed one error but I can’t find where else I’m calling getelementbyid
Uncaught TypeError: document.getElementById(…) is null
There was two of these. I checked my project settings.