Javascript Hide/Show Button Does Not Work Properly

I want to add Javascript show/hide button to show and hide a dive element of my page.

This is my code:

while($r = $query->fetch(PDO::FETCH_OBJ)){
    echo "
            <title>What is the equivalent?</title>
            <div class='center'>
                <div class='show'>
                    <form action='' method='POST'>
                        <p><input type='submit' value='Show' onclick='myFunction()'></input></p></br>
                        <div id='myDIV'>
                            This is my DIV element.
                    <a href='en-de.php' style='text-decoration:none'>En to De</a>
        function myFunction() {
          var x = document.getElementById('myDIV');
          if ( === 'none') {
   = 'block';
          } else {
   = 'none';

As you can see I have set this <input type='submit' value='Show' onclick='myFunction()'></input> and the myFunction() is called at the bottom between script tags.

But the problem is it does not work out and div within id of myDIV is always shown at the page.

So how to fix this? What’s going wrong here?

22 thoughts on “Javascript Hide/Show Button Does Not Work Properly”