I am working within the constraints of a content management system that sometimes forces me to do some odd things because I don't have full control of the HTML code.
In this instance, I have a situation where I want one DIV to not be nested inside another DIV. Because of the CMS settings, I can't just re-order the DIVs in the HTML code.
So, I have this:
<div class="blog">
<div class="free-me">
Hello world
</div>
</div>
What I need is:
<div class="blog">
</div>
<div class="free-me">
Hello world
</div>
<div class="blog">
</div>
This would be as simple as copying and pasting some lines if I could access the HTML. But, since I can't just change the HTML, what I want to know is if there's any way I can use CSS or JavaScript to close off the blog
DIV so that free-me
can be a sibling.
I tried this (even though I kind of knew it wouldn't work):
.free-me::before {
content: '</div>';
}
As suspected, that just rendered text that said </div>
into the page.
For JavaScript, I'm certainly no expert, but it seems like you can only insert complete elements, with opening and closing tags, with a command like document.createElement('div');
I can't see a clear way to take an existing DIV and close it off.
Is there a way, either with CSS or JavaScript, I can force a DIV to close or insert an ending </div>
tag?
Note: Preferably a non-jQuery solution.