+ How does it work?

The solution uses a Markdown block to hold the questions and answers. For this version of the script it should be the only Markdown block on the page, though I may improve the script at a later date to allow for multiple open/close areas.

A jQuery script then manipulates the Markdown block to add the open/close behaviour.

+ Why Markdown?

The native Squarespace html layouts can be difficult to interpret. Placing a single Markdown block on a page makes it very easy to target with scripting as it has a class of .markdown-block.

Markdown is also easier for a non technical user to edit or add content compared to raw html.

It supports bullet points and other styling codes Markdown blocks can also include html, which opens up the possibility for richer experiences that include imagery and other embedded media.

  • It supports bullet points and other styling codes

Markdown blocks can also include html...

+ Why jQuery

jQuery is a Javascript framework that removes a lot of complexity when coding solutions that need to work on multiple web browsers.

This open/close functionality is expressed in 4 lines of jQuery code (excluding the call to the main jQuery library) whereas a pure Javascript solution would be far longer.

It's true that the jQuery library can add page load time, but in my code I link to the one hosted on Google's content delivery network, which means there's a strong chance that a user already has the jQuery library in their browser cache.