-1

I have a small piece of code and i wanted to know that how can I do when I click on outside div class="gutte" and this div should be go focusout. I snippet my code down and this is not focusout when I click on outside of div class="gutte" (or <body> ) and i cannot use input type[text]. When I click on btn1 div class="gutte" focus but one I click on another part (in input type text) it goes focusout.. How could I do this ? I am using jQuery framework.

var tt = $.noConflict();
tt(document).ready(function($) {
  $(".qta").focus(function() {

    $(".gutt").css({
      'display': 'inline-block'
    });
    $(".gutte").addClass('grandisciti');
  });

  $(".gutte").focusout(function() {

    $(".gutt").css({
      'display': 'none'
    });
    $(".gutte").removeClass('grandisciti');
  });
});
body {
   width: 100%;
   height: 100%;
   background-color: #c1c2c3;
 }
 .gutte {
   box-sizing: border-box;
   position: relative;
   display: block;
   width: 550px;
   height: 50px;
   background-color: #fff;
   color: #000;
   margin: 0px;
   padding: 0px;
   margin-left: 32%;
   margin-top: 30px;
   padding-top: 2.5px;
   padding-left: 1px;
   padding-bottom: 2px;
   border-radius: 10px;
   border-radius: 10px;
   text-align: center;
 }
 .ati {
   box-sizing: border-box;
   position: static;
   display: inline-block;
   width: 105px;
   height: 45px;
   margin: 0px;
   padding: 0px;
   padding: 0px 10px;
   border: none;
   background-color: #ccc;
   /*border:2px solid #ccc;*/
   border-radius: 10px;
   outline: none;
   cursor: pointer;
   transition: 0.8s all;
   font-size: 120%;
   color: #000;
 }
 .grandisciti {
   width: 600;
   height: 300px;
   -webkit-box-shadow: 2px 2px 5px 6px rgba(0, 0, 0, 0.5);
   -moz-box-shadow: 2px 2px 5px 6px rgba(0, 0, 0, 0.5);
   box-shadow: 2px 2px 5px 6px rgba(0, 0, 0, 0.5);
 }
 .gutt {
   display: none;
   width: 530px;
      margin:10px;
   background-color: #000;
 }
 .tref {
   display: inline-block;
   width: 80%;
   height: 100px;
   resize: none;
   outline: none;
   padding: 10px;
   margin: 15px;
   border: 5px solid #ccc;
 }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

body
<div tabindex="1" class="gutte">
  <div  class="irj fjr_p05gure rddre ">
    <button class="ati qta ">btn1</button>
    <button class="ati ">btn2</button>
    <button class="ati ">bt3</button>

  </div>
  <span class="gutt">
    <input type="text" class="tref"/>
  </span>

</div>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Phoenix
  • 467
  • 1
  • 11
  • 23

1 Answers1

1

When you focus in a element, any element that has focused make focusout, then target element make focused. See this example for better understanding.

$("input").focus(function(){
    console.log(this.name + " focused");
}).blur(function(){
    console.log(this.name + " blured");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="A" /> 
<input name="B" /> 
<input name="C" />

You need to add focus event to any button like this:

Answer: Jsfiddle

Mohammad
  • 21,175
  • 15
  • 55
  • 84
  • PS: blur and focusout behave differently: blur only applies to the object itself, and focusout bubbles up: if one of your inputfields has no focus, the containing DIV also fires the focusout event. – wintvelt Nov 25 '15 at 14:16
  • dont work . when u click on text area it goes foucust – Phoenix Nov 25 '15 at 19:42