Skip to content

Instantly share code, notes, and snippets.

@beatrizsmerino
Last active January 27, 2021 16:44
Show Gist options
  • Save beatrizsmerino/cf3f2f603b23a4de0df57b08b4e2ba50 to your computer and use it in GitHub Desktop.
Save beatrizsmerino/cf3f2f603b23a4de0df57b08b4e2ba50 to your computer and use it in GitHub Desktop.
Insert file sprites.svg with the icons to the end of the all html files
/*
* COMPONENTS
* sprites
* =================================================
*/
/**
* @function printSprites
* @description Insert file sprites.svg with the icons to the end of the all html files
*/
function printSprites() {
const url = '../../images/icons/sprites.svg';
const className = 'sprite';
const getContentFile = async(urlFile) => {
const getData = await fetch(urlFile);
const data = await getData.text();
return data;
};
getContentFile(url).then((data) => {
const contentSprites = document.createElement('div');
contentSprites.setAttribute('class', className);
document.querySelector('body').appendChild(contentSprites);
contentSprites.insertAdjacentHTML('beforeend', data);
});
}
(function() {
printSprites();
}());
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Sprites
</title>
</head>
<body>
<svg class="icon icon-menu">
<use xlink:href="#icon-menu" href="#icon-menu"></use>
</svg>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment