Show/Hide div on click and disappears after clicking outside the div
up vote
0
down vote
favorite
Will someone do to me so that after clicking outside the div - div disappeared? Because now it disappears only when you click Click to Show / Hide div
again
$(document).ready(function()
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
jquery
add a comment |
up vote
0
down vote
favorite
Will someone do to me so that after clicking outside the div - div disappeared? Because now it disappears only when you click Click to Show / Hide div
again
$(document).ready(function()
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
jquery
after clicking outside the div
- whichdiv
are you talking about (#show
or.menu
)?
– Tân Nguyễn
19 hours ago
.menu (the one that appears after clicking in #menu)
– Lukasz Staszewski
19 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Will someone do to me so that after clicking outside the div - div disappeared? Because now it disappears only when you click Click to Show / Hide div
again
$(document).ready(function()
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
jquery
Will someone do to me so that after clicking outside the div - div disappeared? Because now it disappears only when you click Click to Show / Hide div
again
$(document).ready(function()
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
$(document).ready(function()
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
$(document).ready(function()
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
);
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
jquery
jquery
edited 19 hours ago
Tân Nguyễn
2,99132048
2,99132048
asked 20 hours ago
Lukasz Staszewski
63
63
after clicking outside the div
- whichdiv
are you talking about (#show
or.menu
)?
– Tân Nguyễn
19 hours ago
.menu (the one that appears after clicking in #menu)
– Lukasz Staszewski
19 hours ago
add a comment |
after clicking outside the div
- whichdiv
are you talking about (#show
or.menu
)?
– Tân Nguyễn
19 hours ago
.menu (the one that appears after clicking in #menu)
– Lukasz Staszewski
19 hours ago
after clicking outside the div
- which div
are you talking about (#show
or .menu
)?– Tân Nguyễn
19 hours ago
after clicking outside the div
- which div
are you talking about (#show
or .menu
)?– Tân Nguyễn
19 hours ago
.menu (the one that appears after clicking in #menu)
– Lukasz Staszewski
19 hours ago
.menu (the one that appears after clicking in #menu)
– Lukasz Staszewski
19 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I hope this is your requirement.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
//OR
$('.menu').toggle();
);
This will check your clicked element has no id=show
$(document).click(function(e)
if( e.target.id != 'show')
$(".menu").hide();
);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I hope this is your requirement.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
//OR
$('.menu').toggle();
);
This will check your clicked element has no id=show
$(document).click(function(e)
if( e.target.id != 'show')
$(".menu").hide();
);
add a comment |
up vote
0
down vote
accepted
I hope this is your requirement.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
//OR
$('.menu').toggle();
);
This will check your clicked element has no id=show
$(document).click(function(e)
if( e.target.id != 'show')
$(".menu").hide();
);
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I hope this is your requirement.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
//OR
$('.menu').toggle();
);
This will check your clicked element has no id=show
$(document).click(function(e)
if( e.target.id != 'show')
$(".menu").hide();
);
I hope this is your requirement.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="show">Click to Show/ Hide div</div>
<div class="menu" style="display: none;">
<ol>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ol>
</div>
$('#show').click(function()
$('.menu').toggle(1,"linear", "slide");
//OR
$('.menu').toggle();
);
This will check your clicked element has no id=show
$(document).click(function(e)
if( e.target.id != 'show')
$(".menu").hide();
);
answered 19 hours ago
DPS
452112
452112
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237341%2fshow-hide-div-on-click-and-disappears-after-clicking-outside-the-div%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
after clicking outside the div
- whichdiv
are you talking about (#show
or.menu
)?– Tân Nguyễn
19 hours ago
.menu (the one that appears after clicking in #menu)
– Lukasz Staszewski
19 hours ago