There is such a script:

function toggle(el) { el.style.display = (el.style.display == 'none') ? '' : 'none' } 

Calling the script:

 onclick="toggle(tr)" 

If you click toggle (tr) in the onclick div, then a block with id = "tr" appears and in order for this appeared block to disappear you need to click one more time in the div with id "tr, and so, you need to make it so that if you click on any part page block then how to do it?

    2 answers 2

    Any part of the page is a Document object. Implement a "one click" event in the Document and "hide" your div. The Document element (your div) is accessed in order to access the arrays.

    • I do not know js, give an example please - Maxoud
    • 2
      Open Google search or go to the nearest bookstore. Good luck! - Vyacheslav Kirichenko

    HTML:

     <a href="javascript://" id="click-block">Click</a> <div class="block"></div> 

    CSS:

     a { color: #000; font: 14px "Trebuchet MS"; } div.block { display: none; background: #ccc; width: 50px; height: 50px; } 

    Javascript:

     $('#click-block').live('click', function () { var elem = $('div.block'); elem.show(); }); var check = false; $('div.block').hover(function () { check = true; }, function () { check = false; }); $(document.body).live('click', function () { if ( !check ) $('div.block').hide(); }); 

    The result of the execution.

    • Dear exec, I will explain to you Maxoud (or make him comments in the code) where his div is hiding: $ (document.body) .live ('click', function () {if (! Check) $ ('div.block' ) .hide ();}); - Vyacheslav Kirichenko
    • one
      @ Vyacheslav Kirichenko, I did little? Let him seek. - Oleg
    • You Respect. Good luck. - Vyacheslav Kirichenko
    • Why write so much code when this code does something else at all ?! I want the block to disappear when you click on any part of the page, and your code (in the example) does not even disappear when you click on the link, thanks for the effort, no one helped me, unless you were rude, but it’s interesting to advertise the site when you don’t are you helping? do you tell give advice? so who needs them?!))) - Maksud