Your invocation of toggle_visibility()
in HTML isn't matching code in JS for
if (cl instanceof Array)
isn't true
, thus it's toggling all buttons declared with class myContent
. cl
in function returned from toggle_visibility()
is first argument of invocation, which is 'myContent'
in your case. But I think you want either use arguments
rather than cl
there or wrap the list of names in an array on invocation like this:
toggle_visibility( [ 'myContent', 'close_btn', 'open_btn' ] );
But this won't fix your issue nevertheless.
What about click handler like this:
function toggle_visibility(event) {
event.target.style.display = window.getComputedStyle(event.target, null).style == 'none' ? 'block' : 'none';
return false;
}
Note: see https://developer.mozilla.org/en-US/docs/Web/API/event.target
In your HTML you might use
<a href="#" onclick="toggle_visibility();">Link</a>
See that example in addition: https://developer.mozilla.org/en-US/docs/Web/API/event.currentTarget