I want to hide the heading above a div if said div is empty. the content of the content div will change due to user input. What I expect is heading1 to appear as soon as the button is clicked.
I'd prefer a css solution, but I am allready using jquery and a lot of javascript on the page, so I am open to all solutions.
it is possible to give all headings a unique ID, if that makes things easier
function addcontent()
{
document.getElementById("Content1").innerHTML = "Extra Content";
}
$(".rulescontent:empty").parent().hide();
$(!".rulescontent:empty").parent().show();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<h1>heading1</h1>
<div style="font-size:90%" id="Content1" class="rulescontent"></div>
</div>
<div>
<h1>heading2</h1>
<div style="font-size:90%" id="Content2" class="rulescontent"></div>
</div>
<button type='button' onclick="addcontent()">add content</button>
other Stakcoverflow solutions also don't let content reappear once it is not empty anymore.