1

I have a problem with my script. To show div, you have to click on link. But to hide it, you can click anywhere outside of div. How can I make this div close only after clicking on link?

http://jsfiddle.net/N4pbP/

$(function() {
  $('#hidden').hide().click(function(e) {
    e.stopPropagation();
  });      
  $("a").click(function(e) {
    $('#hidden').animate({ opacity: "toggle" });

    e.stopPropagation();
  });
  $(document).click(function() {
    $('#hidden').fadeOut();
  });
});
3
  • why you want $(document).click(function() { $('#hidden').fadeOut(); }); function?? Commented Nov 16, 2013 at 14:06
  • 1
    You already have the toggling effect on your a, just get rid of the document part. Commented Nov 16, 2013 at 14:06
  • jsfiddle.net/N4pbP/4 Commented Nov 16, 2013 at 14:08

2 Answers 2

3

try with .blur() like this:

$("a").blur(function(e) {
    $('#hidden').fadeOut();
  });

DEMO

Sign up to request clarification or add additional context in comments.

Comments

1

I don't know much about jquery, but I changed the code on the last function to:

  $document.getElementById('test').click(function() {
    $('#hidden').fadeOut();
  });

And it worked

Fiddle: http://jsfiddle.net/N4pbP/3/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.