Last active
April 8, 2020 16:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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