Скрыть только один родитель елем.
по клику на blockInsertTask он тоже скрывается как и по клику на .container
$(".blockInsertTask").fadeOut(); Как сделать чтобы блок не скрывался по клику на него(blockInsertTask) скрывался только на .container <div class="container"> <button class="btnInsert">Добавить задачу</button> <div class="blockInsertTask"> блок </div> </div> $(".btnInsert").click(function (ob) { ob.stopPropagation(); $(".blockInsertTask").fadeIn(); }); $(".container").click(function () { $(".blockInsertTask").fadeOut(); }); |
A1x1On2015,
<!DOCTYPE HTML> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style type="text/css"> .container { background-color: #FF0000; padding: 20px; } .btnInsert { background: #FFCC00; cursor: pointer; } .blockInsertTask{ display: none; background-color: #00FF00; height: 200px; } </style> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> $(function() { $(".container").click(function(event) { if (!$(event.target).is(".blockInsertTask")) $(".blockInsertTask")[$(event.target).is(".btnInsert") ? "fadeIn" : "fadeOut"]() }) }); </script> </head> <body> <div class="container"> <button class="btnInsert">Добавить задачу</button> <div class="blockInsertTask"> блок </div> </div> </body> </html> |
Спасибо!
|
Часовой пояс GMT +3, время: 16:11. |