1
<script>
    function toggle_table() {
        visibility = document.getElementById("table").style.visibility;
        document.getElementById("table").style.visibility = (visibility == 'visible') ? 'hidden' : 'visible';
        document.getElementById("toggle_table").innerHTML = (visibility == 'visible') ? 'Open' : 'Close';
    }
</script>

<form method='POST'>
    <a id='toggle_table' href='#' onClick='toggle_table()'>Open</a> WIJZIGEN PROCES
    <table id='table' style='visibility: hidden'>
    </table>
</form>

This works great. Though I don't want to just make it invisible, I want to not render the innerHTML (so it won't take it's space when invisible). Similar to this question, though I cannot make use of JQuery (requirements). Is this in a rather simple way with plain JavaScript, without the need of putting the whole HTML-content in Javascript?

1
  • use display:none to hide it from DOM, not visibility Commented Mar 15, 2013 at 10:37

3 Answers 3

1

Use display:

document.getElementById("table").style.display = (display == 'none') ? '' : 'none';
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, you were right. This appears to be a CSS issue, not JS. Will accept as soon as possible.
0

You may try this using display property

function toggle_table() {
    display = document.getElementById("table").style.display;
    document.getElementById("table").style.display= (display != 'none') ? 'none' : 'table';
    document.getElementById("toggle_table").innerHTML = (display== 'table') ? 'Open' : 'Close';
}

Comments

0

Use display:table and display:none instead of visibility:hidden/visible

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.