Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Скрыть только один родитель елем. (https://javascript.ru/forum/jquery/57966-skryt-tolko-odin-roditel-elem.html)

A1x1On2015 28.08.2015 12:27

Скрыть только один родитель елем.
 
по клику на 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();
    });

рони 28.08.2015 13:02

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>

A1x1On2015 28.08.2015 14:02

Спасибо!


Часовой пояс GMT +3, время: 16:11.