It’s kind of strange that I have to click twice to see Foo’s content, but only once to see Bar’s content. The main difference seems to be that Foo’s content has internal style while Bar has inline style.
<html>
<head>
<style>
.content {
display: none;
}
</style>
<script>
function showHide(element) {
sibling = element.nextElementSibling;
if (sibling.style.display == "none")
sibling.style.display = "block"
else sibling.style.display = "none";
}
</script>
</head>
<body>
<h1 onclick="showHide(this)">Foo</h1>
<div class="content">
Foo Content
</div>
<h1 onclick="showHide(this)">Bar</h1>
<div style="display: none;">
Bar Content
</div>
</body>
</html>
You can find the code on jsfiddle here
I’m really interested in achieving the same behavior with internal CSS or external CSS that I currently have with inline CSS. Do you think this is possible? I know it might be a simple issue, but I’m not quite sure which concepts to explore further.