Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  16] [ 6]  / answers: 1 / hits: 29071  / 12 Years ago, fri, february 24, 2012, 12:00:00

I would like to open email-signup when I click on email-signup-link. Then I would like to close it by clicking anywhere on the page except for the box itself, of course.



I have looked around on this site and there are various solutions for this problem but every one I've tried shows and then hides my div instantly. I must be doing something wrong.



This is the HTML:



<a href=# id=email-signup-link>Sign Up</a>
<div id=email-signup>
<div id=inner>
<h2>E-mail Notifications</h2>
<input class= type=text name=description placeholder=Enter your e-mail address id=description />
<a href=#>Sign Up</a>
</div>
</div>


This is my Javascript:



$('#email-signup').click(function(){
e.stopPropagation();
});
$(#email-signup-link).click(function() {
e.preventDefault();
$('#email-signup').show();
});
$(document).click(function() {
$('#email-signup').hide();
});

More From » html

 Answers
29

Two things. You don't actually have e defined, so you can't use it. And you need stopPropagation in your other click handler as well:



$('#email-signup').click(function(e){
e.stopPropagation();
});
$(#email-signup-link).click(function(e) {
e.preventDefault();
e.stopPropagation();
$('#email-signup').show();
});
$(document).click(function() {
$('#email-signup').hide();
});​


http://jsfiddle.net/Nczpb/


[#87222] Thursday, February 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;