How to check if a div is visible state or not?
I have tabs like this.
<li id="singlechatpanel-1" style="visibility: hidden;">
//content
</li>
Trying to check it like this:
$(".subpanel a").click(function()
{
var chatterNickname = $(this).text();
if(!$("#singlechatpanel-1").is(':visible'))
alert("Room 1 is filled.");
$("#singlechatpanel-1").css('visibility':'visible');
$("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);
If condition always returns false. How can I check visibility state of this div?
jquery
add a comment |
I have tabs like this.
<li id="singlechatpanel-1" style="visibility: hidden;">
//content
</li>
Trying to check it like this:
$(".subpanel a").click(function()
{
var chatterNickname = $(this).text();
if(!$("#singlechatpanel-1").is(':visible'))
alert("Room 1 is filled.");
$("#singlechatpanel-1").css('visibility':'visible');
$("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);
If condition always returns false. How can I check visibility state of this div?
jquery
1
stackoverflow.com/questions/178325/…
– Johnny Mopp
Sep 10 '12 at 14:28
add a comment |
I have tabs like this.
<li id="singlechatpanel-1" style="visibility: hidden;">
//content
</li>
Trying to check it like this:
$(".subpanel a").click(function()
{
var chatterNickname = $(this).text();
if(!$("#singlechatpanel-1").is(':visible'))
alert("Room 1 is filled.");
$("#singlechatpanel-1").css('visibility':'visible');
$("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);
If condition always returns false. How can I check visibility state of this div?
jquery
I have tabs like this.
<li id="singlechatpanel-1" style="visibility: hidden;">
//content
</li>
Trying to check it like this:
$(".subpanel a").click(function()
{
var chatterNickname = $(this).text();
if(!$("#singlechatpanel-1").is(':visible'))
alert("Room 1 is filled.");
$("#singlechatpanel-1").css('visibility':'visible');
$("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);
If condition always returns false. How can I check visibility state of this div?
jquery
jquery
asked Sep 10 '12 at 14:25
AristonaAristona
3,23273870
3,23273870
1
stackoverflow.com/questions/178325/…
– Johnny Mopp
Sep 10 '12 at 14:28
add a comment |
1
stackoverflow.com/questions/178325/…
– Johnny Mopp
Sep 10 '12 at 14:28
1
1
stackoverflow.com/questions/178325/…
– Johnny Mopp
Sep 10 '12 at 14:28
stackoverflow.com/questions/178325/…
– Johnny Mopp
Sep 10 '12 at 14:28
add a comment |
7 Answers
7
active
oldest
votes
is(':visible')
checks the display
property of an element, you can use css
method.
if (!$("#singlechatpanel-1").css('visibility') === 'hidden')
// ...
If you set the display
property of the element to none
then your if
statement returns true
.
Solved. Thank you.
– Aristona
Sep 10 '12 at 14:35
One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S
– bitanath
Jun 5 '17 at 10:24
@bitanath Please check this related question: stackoverflow.com/questions/133051/…
– undefined
Jun 6 '17 at 0:12
Yeah it makes sense now, thanks @undefined
– bitanath
Jun 6 '17 at 6:07
add a comment |
Check if it's visible.
$("#singlechatpanel-1").is(':visible');
Check if it's hidden.
$("#singlechatpanel-1").is(':hidden');
add a comment |
if element is hide by jquery then use
if($("#elmentid").is(':hidden'))
add a comment |
You can use .css()
to get the value of "visibility":
if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))
http://api.jquery.com/css/
add a comment |
You can use (':hidden') method to find if your div is visible or not..
Also its a good practice to cache a element if you are using it multiple times in your code..
$(".subpanel a").click(function()
var chatterNickname = $(this).text();
var $chatPanel = $("#singlechatpanel-1");
if(!$chatPanel.is(':hidden'))
alert("Room 1 is filled.");
$chatPanel.show();
$("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);
);
add a comment |
if (!$('#singlechatpanel-1').css('display') == 'none')
alert('visible');
else
alert('hidden');
add a comment |
Add your li
to a class, and do $(".myclass").hide();
at the start to hide it instead of the visibility style attribute.
As far as I know, jquery uses the display
style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)
add a comment |
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12353741%2fhow-to-check-if-a-div-is-visible-state-or-not%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
is(':visible')
checks the display
property of an element, you can use css
method.
if (!$("#singlechatpanel-1").css('visibility') === 'hidden')
// ...
If you set the display
property of the element to none
then your if
statement returns true
.
Solved. Thank you.
– Aristona
Sep 10 '12 at 14:35
One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S
– bitanath
Jun 5 '17 at 10:24
@bitanath Please check this related question: stackoverflow.com/questions/133051/…
– undefined
Jun 6 '17 at 0:12
Yeah it makes sense now, thanks @undefined
– bitanath
Jun 6 '17 at 6:07
add a comment |
is(':visible')
checks the display
property of an element, you can use css
method.
if (!$("#singlechatpanel-1").css('visibility') === 'hidden')
// ...
If you set the display
property of the element to none
then your if
statement returns true
.
Solved. Thank you.
– Aristona
Sep 10 '12 at 14:35
One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S
– bitanath
Jun 5 '17 at 10:24
@bitanath Please check this related question: stackoverflow.com/questions/133051/…
– undefined
Jun 6 '17 at 0:12
Yeah it makes sense now, thanks @undefined
– bitanath
Jun 6 '17 at 6:07
add a comment |
is(':visible')
checks the display
property of an element, you can use css
method.
if (!$("#singlechatpanel-1").css('visibility') === 'hidden')
// ...
If you set the display
property of the element to none
then your if
statement returns true
.
is(':visible')
checks the display
property of an element, you can use css
method.
if (!$("#singlechatpanel-1").css('visibility') === 'hidden')
// ...
If you set the display
property of the element to none
then your if
statement returns true
.
edited Apr 2 '13 at 5:31
answered Sep 10 '12 at 14:30
undefinedundefined
125k12133171
125k12133171
Solved. Thank you.
– Aristona
Sep 10 '12 at 14:35
One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S
– bitanath
Jun 5 '17 at 10:24
@bitanath Please check this related question: stackoverflow.com/questions/133051/…
– undefined
Jun 6 '17 at 0:12
Yeah it makes sense now, thanks @undefined
– bitanath
Jun 6 '17 at 6:07
add a comment |
Solved. Thank you.
– Aristona
Sep 10 '12 at 14:35
One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S
– bitanath
Jun 5 '17 at 10:24
@bitanath Please check this related question: stackoverflow.com/questions/133051/…
– undefined
Jun 6 '17 at 0:12
Yeah it makes sense now, thanks @undefined
– bitanath
Jun 6 '17 at 6:07
Solved. Thank you.
– Aristona
Sep 10 '12 at 14:35
Solved. Thank you.
– Aristona
Sep 10 '12 at 14:35
One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S
– bitanath
Jun 5 '17 at 10:24
One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S
– bitanath
Jun 5 '17 at 10:24
@bitanath Please check this related question: stackoverflow.com/questions/133051/…
– undefined
Jun 6 '17 at 0:12
@bitanath Please check this related question: stackoverflow.com/questions/133051/…
– undefined
Jun 6 '17 at 0:12
Yeah it makes sense now, thanks @undefined
– bitanath
Jun 6 '17 at 6:07
Yeah it makes sense now, thanks @undefined
– bitanath
Jun 6 '17 at 6:07
add a comment |
Check if it's visible.
$("#singlechatpanel-1").is(':visible');
Check if it's hidden.
$("#singlechatpanel-1").is(':hidden');
add a comment |
Check if it's visible.
$("#singlechatpanel-1").is(':visible');
Check if it's hidden.
$("#singlechatpanel-1").is(':hidden');
add a comment |
Check if it's visible.
$("#singlechatpanel-1").is(':visible');
Check if it's hidden.
$("#singlechatpanel-1").is(':hidden');
Check if it's visible.
$("#singlechatpanel-1").is(':visible');
Check if it's hidden.
$("#singlechatpanel-1").is(':hidden');
edited Oct 27 '14 at 17:25
Joshua Pinter
25.3k9142172
25.3k9142172
answered May 29 '14 at 11:14
Vipin Kumar R. JaiswarVipin Kumar R. Jaiswar
60654
60654
add a comment |
add a comment |
if element is hide by jquery then use
if($("#elmentid").is(':hidden'))
add a comment |
if element is hide by jquery then use
if($("#elmentid").is(':hidden'))
add a comment |
if element is hide by jquery then use
if($("#elmentid").is(':hidden'))
if element is hide by jquery then use
if($("#elmentid").is(':hidden'))
edited Mar 11 '15 at 9:59
NorthCat
6,090153239
6,090153239
answered Mar 11 '15 at 9:37
Shah NawazShah Nawaz
33129
33129
add a comment |
add a comment |
You can use .css()
to get the value of "visibility":
if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))
http://api.jquery.com/css/
add a comment |
You can use .css()
to get the value of "visibility":
if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))
http://api.jquery.com/css/
add a comment |
You can use .css()
to get the value of "visibility":
if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))
http://api.jquery.com/css/
You can use .css()
to get the value of "visibility":
if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))
http://api.jquery.com/css/
edited Nov 15 '18 at 5:13
Ajay2707
4,36942345
4,36942345
answered Sep 10 '12 at 14:29
Pablo MartinezPablo Martinez
1,9191520
1,9191520
add a comment |
add a comment |
You can use (':hidden') method to find if your div is visible or not..
Also its a good practice to cache a element if you are using it multiple times in your code..
$(".subpanel a").click(function()
var chatterNickname = $(this).text();
var $chatPanel = $("#singlechatpanel-1");
if(!$chatPanel.is(':hidden'))
alert("Room 1 is filled.");
$chatPanel.show();
$("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);
);
add a comment |
You can use (':hidden') method to find if your div is visible or not..
Also its a good practice to cache a element if you are using it multiple times in your code..
$(".subpanel a").click(function()
var chatterNickname = $(this).text();
var $chatPanel = $("#singlechatpanel-1");
if(!$chatPanel.is(':hidden'))
alert("Room 1 is filled.");
$chatPanel.show();
$("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);
);
add a comment |
You can use (':hidden') method to find if your div is visible or not..
Also its a good practice to cache a element if you are using it multiple times in your code..
$(".subpanel a").click(function()
var chatterNickname = $(this).text();
var $chatPanel = $("#singlechatpanel-1");
if(!$chatPanel.is(':hidden'))
alert("Room 1 is filled.");
$chatPanel.show();
$("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);
);
You can use (':hidden') method to find if your div is visible or not..
Also its a good practice to cache a element if you are using it multiple times in your code..
$(".subpanel a").click(function()
var chatterNickname = $(this).text();
var $chatPanel = $("#singlechatpanel-1");
if(!$chatPanel.is(':hidden'))
alert("Room 1 is filled.");
$chatPanel.show();
$("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);
);
answered Sep 10 '12 at 15:20
Sushanth --Sushanth --
50.6k64885
50.6k64885
add a comment |
add a comment |
if (!$('#singlechatpanel-1').css('display') == 'none')
alert('visible');
else
alert('hidden');
add a comment |
if (!$('#singlechatpanel-1').css('display') == 'none')
alert('visible');
else
alert('hidden');
add a comment |
if (!$('#singlechatpanel-1').css('display') == 'none')
alert('visible');
else
alert('hidden');
if (!$('#singlechatpanel-1').css('display') == 'none')
alert('visible');
else
alert('hidden');
answered Sep 1 '15 at 9:55
PrabhagaranPrabhagaran
2,3411217
2,3411217
add a comment |
add a comment |
Add your li
to a class, and do $(".myclass").hide();
at the start to hide it instead of the visibility style attribute.
As far as I know, jquery uses the display
style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)
add a comment |
Add your li
to a class, and do $(".myclass").hide();
at the start to hide it instead of the visibility style attribute.
As far as I know, jquery uses the display
style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)
add a comment |
Add your li
to a class, and do $(".myclass").hide();
at the start to hide it instead of the visibility style attribute.
As far as I know, jquery uses the display
style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)
Add your li
to a class, and do $(".myclass").hide();
at the start to hide it instead of the visibility style attribute.
As far as I know, jquery uses the display
style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)
answered Sep 10 '12 at 14:33
PhonicUKPhonicUK
10.4k22854
10.4k22854
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12353741%2fhow-to-check-if-a-div-is-visible-state-or-not%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
stackoverflow.com/questions/178325/…
– Johnny Mopp
Sep 10 '12 at 14:28