javascript - how to trigger an event for an element when some other element is clicked in jQuery? -


here code: https://jsfiddle.net/2vvle0ko/2/

i want hide div class droppointercontainer when user clicks other region except click me! div. , show droppointercontainer div when user clicks click me! div.

how jquery?

html:

<body>   <div class="click" id="click1">click me!                       <div class="droppointercontainer" id="droppointercontainer1">                         <div class="droppointer"></div>                         <div class="dropmenu" id="dropmenu1">                             <h4>option1</h4>                             <h4>option2</h4>                             <h4>option3</h4>                         </div>                         <div class="dropmenutop"></div>                     </div>   </div>   <div class = "click" id="click2">click me!                       <div class="droppointercontainer" id="droppointercontainer2">                         <div class="droppointer"></div>                         <div class="dropmenu" id="dropmenu1">                             <h4>option1</h4>                             <h4>option2</h4>                             <h4>option3</h4>                         </div>                         <div class="dropmenutop"></div>                     </div>   </div>    <div class = "static">iam  tatic div</div>    <div class = "static">iam  tatic div</div>    <div class = "static">iam  tatic div</div> </body> 

css:

.click{   display:inline-block;   margin: 10px;   padding: 10px;   background-color: purple;   color: white; } .static{   background-color:steelblue;   height: 100px; } .droppointer{   /*display: none;*/   position: absolute;   margin: 0 auto;   width: 0;   right: 0;   border: 10px solid transparent;   border-bottom: 10px solid #efefef;   border-top: 0px;    z-index: 200; } .droppointercontainer{   display:none;   position: relative;   width: 100%;   margin: 0 auto;   background-color: blue; } .dropmenutop{   /*display: none;*/   background-color: transparent;   position: absolute;   height: 10px;   left: 0;   right: 0;   z-index: 199; } .dropmenu{   /*display: none;*/   box-shadow: 0 0 15px #888888;   background-color: #efefef;   position: absolute;   margin-top: 10px;   min-height: 20px;   left: 0px;   right: 0px;   z-index: 199; } h4{   color:black; } 

javascript:

$("#click1").on("click", function(){     $(this).children("#droppointercontainer1").fadein(200); }); $("#click2").on("click", function(){     $(this).children("#droppointercontainer2").fadein(200); }); 

you need call function job clicks...

edited , added working proof link.

$("#click1").on("click", function(){     showme(this); }); $("#click2").on("click", function(){      showme(this); });  $(document).on('click', function(__e){       if(!$(__e.target).hasclass('click')){          $('.droppointercontainer').fadeout(200);       }        });  function showme(__obj){   $('.droppointercontainer').each(function(__idx, __el){         if($(__el)[0] !== $(__obj).children('.droppointercontainer:first')[0]){         if($(__el).css('opacity') >  0){         $(__el).fadeout(200);       }     } }); $(__obj).children('.droppointercontainer:first').fadein(200);    } 

proof

https://jsfiddle.net/2vvle0ko/7/


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -