Here i'm trying to remove the link tags from head based on the flag value. based on the flag value i'm removing the link tags from head and creating new tags.
in the below code whats happening is i'm able to remove only the last link tag, but not all the link tags from the head tag. not sure why its happening.
Here is what i have tried.
let bootstrapTheme = true;
let head = document.getElementsByTagName('head')[0],
stylesheets = ['https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js','https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js']
var link;
stylesheets.forEach(function(stylesheet) {
link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = stylesheet;
head.appendChild(link);
});
if(!bootstrapTheme){
link.parentNode.removeChild(link);
}