By using this method I can show/hide an element by using 2 buttons:
<script type="text/javascript">
function showStuff(id) {
document.getElementById(id).style.display = 'block';
}
function hideStuff(id) {
document.getElementById(id).style.display = 'none';
}
</script>
<input type="button" onClick="hideStuff('themes')" value="Hide">
<input type="button" onClick="showStuff('themes')" value="Show">
<div id="themes" style="display:block">
<h3>Stuff</h3>
</div>
Is there a method to use a single button?? Maybe if & else?
You’ve already answered your question…the use of
if/else:This won’t be completely foolproof, in case you are hiding/showing
inlineorinline-blockelements, or if you are using non-default values fordisplayon elements…such as setting a div’sdisplayto “inline” (for whatever reason) and then trying to use this function