Hello I'm fairly new to java but I am learning quick.
I am working on a website that uses .tpl files mainly to control content on pages.
Currently I am running this:
Code:
<a href="#"
onclick="document.getElementById('text1').style.display='block';">Question numero uno</a>
<div id="text1" style="display:none;">
This text is revealed by button 1 and hidden by button 3.
<a href="#"
onclick="document.getElementById('text1').style.display = 'none';">
hide</div></a>
The question is clicked, the answer shows, and they have the option to hide it again.
I would much rather have the person click the question again to hide the answer and not have to click "hide"
Since I am dealing in .tpl files this code i found doesn't work at all
Code:
<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
//-->
</script>
And the usage would be
Code:
<a href="#" onclick="toggle_visibility('foo');">Click here to toggle visibility of element #foo</a>
<div id="foo">This is foo</div>
I believe it would work if I could use a single line. Without having to establish variables.
I was thinking
Code:
if{document.getElementById('text1').style.display='block' onclick="document.getElementById('text1').style.display='none'}
else onclick="document.getElementById('text1').style.display='block'}
but i can't figure out the proper usage.
Bookmarks