Skip to content

Instantly share code, notes, and snippets.

@ryandejaegher
Last active April 8, 2020 16:49
Show Gist options
  • Select an option

  • Save ryandejaegher/181fbf99d6e9222d700cd3095016fdc8 to your computer and use it in GitHub Desktop.

Select an option

Save ryandejaegher/181fbf99d6e9222d700cd3095016fdc8 to your computer and use it in GitHub Desktop.
This is a simple code to add HTML to either side of links in Squarespace
/*
Add Icons to HTML Links JavaScript
Demo
addHeaderHTML(getLink('/contact'),'before','<span>Cool</span>')
addHeaderHTML(getLink('/contact'),'before','<span>Cool</span>')
*/
var links = document.querySelectorAll('header a');
var getLink = function(link) {
return document.querySelector(`[href="${link}"]`)
}
function addHeaderHTML(linkSelector, position, html) {
if(position === 'before') {
linkSelector.insertAdjacentHTML('afterbegin',html)
} else if (position === 'after') {
linkSelector.insertAdjacentHTML('beforeend',html)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment