I have a function written to open / close a div using a placeholder for a hyperlink.
<a class="button" onclick="show('click-drop')">Open</a>
The onclick
event then opens the div.
I have this onclick
to close it:
<a class="button" onclick="hide('click-drop')">Close</a>
What I would like to do is have a single placeholder for a hyperlink that switches between the two onclick
events. So onclick=show
would switch to onclick=hide
and vice versa.
I have looked everywhere and cannot find a straightforward solution for my situation.
Revised Question
Here's specifically what I am working with.
function show(target) {
document.getElementById(target).style.height = '300px';
}
function hide(target) {
document.getElementById(target).style.height = '0px';
}
<a class="button" onclick="show('click-drop')">Open</a>
<div id="click-drop" style="height:0px">
<a class="button" onclick="hide('click-drop')">Close</a>
</div>
Click Open
and it opens / expands inline height style. Click Close
and it closes.
I need to have the onclick
toggle, but with Open
changing to Close
and reverse.
It would be ideal to keep the placement of the links. So the Open
link outside the link is hidden until the Close
link within the div is clicked.
I appreciate any feedback.