how can i check using jQuery if something is hidden?
I want to check if a element is hidden based on that i want to add a condition. I just want to use jQu开发者_Go百科ery please help me with that.
I have actually a selectbox which is having id param. When it is hidden I do not want to perform any action but when it is visible and having value as country I want to show next select box containing countries.
param = $('#param').val();
if(param =='country') {//show next box}
I am not sure how to incorporate that show next box only when it is visible
if ($(selector).is(":hidden")){
// hidden
}
else {
// visible
}
In your case it's totally different matter. What you need is such code:
param = jQuery("#param").val();
if(param =='country' && $("#" + param).is(":visible")) {
//do something....
}
You need to pass param
as variable to the jQuery selector, then it will look for element with ID of country
(the value of the variable) and check if it's visible.
Edit: regarding your new edit, try such code:
var oParam = $('#param');
if (oParam.is(":visible")) {
paramValue = oParam.val();
if(paramValue == 'country') {
//show next box
}
}
This will check the value and show next box only when param
is visible.
is_hidden = ($('...').css('display') == 'none' || $('...').css('visibility') == 'hidden');
if (is_hidden) {
// what you want
}
Hi you can do this with $(..elementSelector..).is(':hidden') returns boolean.
精彩评论