I know how to add a css element to a header using JS but how do I remove one?
To add :
var style = document.createElement('style');
style.type = 'text/css';
style.innerHtml = ".item {color:red}";
document.getElementsByTagName('head')[0].appendChild(style);
My question is how can I remove the element, I tried
document.getElementsByTagName('head')[0].removeChild(style);
It throws up an error, I want to remove the css and not throw an error if it doesn't exist.
Your help is most appreciated.
I do not want to use JQuery.
The actual solution based on Daniels that I used is :-
var DeskTag = document.getElementById('style');
if (DeskTag!=null) {
document.getElementsByTagName('head')[0].removeChild(DeskTag);
}
textContent, notinnerhtml(or even the correctly spelledinnerHTML).