I'm sure this is incredibly simple but I'm pretty new to JS and I'd like to know the best way of doing this rather than hacking it out with a workaround.
So I have a div block and it's visibility is toggled when pressing a text field above it.
<h3 onclick="javascript: toggle1();">
<span style="cursor:pointer">
<b>Text1</b>
</span>
</h3>
<div id="Text1" hidden="hidden">blahblah</div>
And then I have my JS:
function toggle1() {
$('#Text1').toggle(1000);
}
This works fine, however when the user clicks the header text I also want to alter the height of a <hr>
element above it
<hr id="line1" style="height:2px;border:none;color:#03930f;background-color:#03930f;" />
I have tried adding:
if($('#Text1').is(':visible')) {
document.getElementById("line1").style.height = "15px";
}
else {
document.getElementById("line1").style.height = "2px";
}
but this doesn't work...I assume because the toggle() function doesn't toggle the same thing the is(':visible')
condition is checking.
What is the correct way of doing this?