Last active
November 20, 2023 04:07
-
-
Save raflyfahrezi/c2d7f3250ea389900b20e5723c0f0da3 to your computer and use it in GitHub Desktop.
Delete all stylesheet link tags at head
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
// 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