Jump to content

Trouble with displaying javascript data

Recommended Posts

I am trying to get a simple javascript array to pass to a squarespace page, but everything I have tried has not worked. Here is the latest code I attempted. I put the script in the Advanced code section for the page, and the HTML in a code section on the page. I can't get anything to display. I am using squarespace 7.1. Any help would be greatly appreciated. Thanks!

 

in advanced code section...
<script>
var array = ['apple','ball']; 
document.getElementById('content').innerHTML = array.toString();
</script>

in code section on page
<div id="content"></div> 
Edited by JamesJ
Link to comment

@tuanphan

is right. What was/is happening is that the code in Page Settings > Advanced > Page Header Code Injection for the page is running before the code block in the page. So the code in the page header can not find the element because it doesn't exist yet. It is an order issue.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.