You need to give your IDs proper names (cannot have spaces), as it is now, your div actually has 3 separate IDs.
and you need to change .style.visibility = 'visible', to .style.visibility = 'hidden' as your original code is not modifying the same style.
<div id="ele1" class="w3-modal" onclick="this.style.visibility='hidden'">
test
</div>
<a onclick="document.getElementById('ele1').style.visibility = 'visible'">X</a>
Notice, in this snippet I had to reverse the way you were trying to hide and show content in the original, because a hidden element is not clickable, if you want to be able to click it. I would use opacity instead, like this:
<div id="ele1" class="w3-modal" onclick="this.style.opacity=100">
test
</div>
<a onclick="document.getElementById('ele1').style.opacity=0">X</a>