I am wondering how people go about appending CSS aswell as removing CSS when it is relevant.
Currently I load pages and append to my documents usually to some other div. This often causes CSS to be mixed into the page for example it would look like this:
<div id="parent">
<style>
.child {
position:absolute;
width: 100%;
height:250px;
border: 1px solid black;
}
</style>
<div class="child"></div>
</div>
Now, although this works, I have always been told that CSS should be in the head of the page not mixed in with HTML. I have not really understood why but I presume there are valid reasons? Many website optimising tools seem to "recommend" putting CSS in the head, aswell as removing unused CSS.
I am wondering how do people append relevant CSS to the page head for loading content, then also remove said CSS once they no longer need it such a removing the content from parent via replacing it with a new html page for example.
Does any one even do it that way or do people just append the way I currently do it?