Last active
March 14, 2019 10:11
-
-
Save AlekVolsk/953c12ebc31209be620aaac39c8d0ed0 to your computer and use it in GitHub Desktop.
Set href to svg-use (for svg-sprite)
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
function svgHref() { | |
var | |
uses = document.querySelectorAll('use'), | |
lhref = location.href.split("#")[0]; | |
for (var i = 0; i < uses.length; i++) { | |
var href = uses[i].getAttribute('xlink:href'); | |
if (href.indexOf('#') == 0) { | |
uses[i].setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', lhref + href); | |
} | |
} | |
} | |
document.addEventListener('DOMContentLoaded', function(){ | |
svgHref(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment