Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide div with jquery when click anywhere except one div? [duplicate]

I am making a search input on focus it shows a div with options with following:

$("#search").focus(function(){

$("#options").fadeIn("fast");

});

I am hiding the div back with this function

 $("#search").blur(function(){

$("#options").fadeOut("fast");

});

now the problem is even when user clicks at any checkbox in #option it hides. How I can stop it hidding when clicking checkboxes?

like image 866
danny Avatar asked May 27 '12 17:05

danny


People also ask

How do I hide a specific div?

We hide the divs by adding a CSS class called hidden to the outer div called . text_container . This will trigger CSS to hide the inner div.

How do you hide a div after a few seconds?

Select the div element. Use delay function (setTimeOut(), delay()) to provide the delay to hide() the div element.

How do I display none when I click outside?

To hide an element when clicked outside: Add a click event listener to the document object. On each click, check if the clicked element is outside of the specific element using the contains() method. If the clicked element is outside, hide the original element.


1 Answers

 $("#search").blur(function(e){
   e.stopPropagation()
   $("#options").fadeOut("fast");
});
like image 155
undefined Avatar answered Oct 08 '22 10:10

undefined