Although I am aware that this may not be the best practice, it seems to be the most suitable solution for this particular case. The server response contains something like this:
<style id="styles">.color_txt{color:green;}</style>
I am attempting to append it to the head
tag:
let styleEl = new DOMParser().parseFromString(res.data.html, "text/xml");
styleEl.type= "text/css";
// Remove current style
document.getElementById('styles').remove();
document.getElementsByTagName('head')[0].appendChild(styleEl.documentElement);
Even though I can see that the new style is added to the head tag, the issue arises when the style is not applied and instead removed from the elements. It's worth mentioning that I am using React
.
//EDIT
I have also noticed that manually adding style via the web console in the newly created style tag doesn't apply it either.