Good day, really need help, there is a script

$(document).ready(function() { $('#contact').click(function () { $( ".right-content" ).animate({ opacity: "toggle"}, 200, "linear", function() { }); }); }); 

How to make it so that when you click outside the .right-content block and the buttons with #contact, the .right-content block collapses? Who can already faced such task?

    2 answers 2

     $(document).on('click', function(event) { if ($(event.target).closest(".right-content, #contact").length) return; // Если ΠΊΠ»ΠΈΠΊ Π² .right-content ΠΈΠ»ΠΈ #contact Π²Ρ‹Ρ…ΠΎΠ΄ΠΈΠΌ ΠΈΠ· Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ $('.right-content').slideUp(); // Если Π½Π΅ Π²Ρ‹ΡˆΠ»ΠΈ - сворачиваСм Π΄ΠΈΠ² }); 

    Example: http://jsfiddle.net/jhkLwub4/

    • Thanks all to the point !!! - Sergeo Ayshev

    Through .one subscribe to click on $(document) , in the handler check that this click is not inside that div. Then hide.