Skip to content

Instantly share code, notes, and snippets.

@raflyfahrezi
Last active November 20, 2023 04:07
Show Gist options
  • Save raflyfahrezi/c2d7f3250ea389900b20e5723c0f0da3 to your computer and use it in GitHub Desktop.
Save raflyfahrezi/c2d7f3250ea389900b20e5723c0f0da3 to your computer and use it in GitHub Desktop.
Delete all stylesheet link tags at head
// Delete Stylesheet
const head = document.head;
const linkTags = head.getElementsByTagName('link');
// Remove all <link> tags that have a 'stylesheet' type
for (let i = linkTags.length - 1; i >= 0; i--) {
const linkTag = linkTags[i];
if (linkTag.getAttribute('rel') === 'stylesheet') {
head.removeChild(linkTag);
}
}
// ---------------------------------------------
// Delete Style Tag
const head = document.head;
const styleTags = head.getElementsByTagName('style');
// Remove all <link> tags that have a 'stylesheet' type
for (let i = styleTags.length - 1; i >= 0; i--) {
const styleTag = styleTags[i];
head.removeChild(styleTag);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment