Tell me, there is such a code

<script type="text/javascript"> function hide(id) {var o=document.getElementById(id).style; o.display=o.display?'': 'none'} </script> 

When you click, it aligns the display to none and the second click displays the display to 0, but you need to, by default, align the display with none. And what if the element lost focus, the value was again reset to none

PS: If I set the display in the CSS table to none by default, the script takes no action.

  • Display from css in e.style is not displayed. o.display=o.display?'none': ''; - confused - Dimava
  • Does not work ((the form is simply to load at all and does not take any action - TomasRedl
  • Everything, understood, re-read, realized))) - TomasRedl
  • How can I make it disappear when clicking on a form? - TomasRedl
  • Easier to say .focusout () - TomasRedl

1 answer 1

The event of loss of focus - blur. hide the default in css and will work

 function hide(id) { var o=document.getElementById(id).style; o.display = o.display == 'none' ? 'block' : 'none'; } document.getElementById('element_id').addEventListener('blur', function(e){ e.target.style.display = 'none'; }); 
  • but what is the hide function here for? - webDev_
  • @webDev_, corrected it simply, when calling and re-clicking it causes it, I did not understand the logic, I simply corrected it - Artem Gorlachev