0

I want to check if a element is hidden based on that i want to add a condition. I just want to use jQuery 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

1
  • i have this condition param = jQuery("#param").val(); if(param =='country' && $("#param").is(":visible")) { which is not working thats why i asked the question Commented Aug 25, 2011 at 10:24

4 Answers 4

0

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.

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

1 Comment

please re read the question its different. I want to pick the value of a visible box.
0
if ($(selector).is(":hidden")){
    // hidden
}
else {
    // visible
}

Comments

0
is_hidden = ($('...').css('display') == 'none' || $('...').css('visibility') == 'hidden');
if (is_hidden) {
    // what you want
}

1 Comment

See Igor answer, jQuery has shortcut for this.
0

Hi you can do this with $(..elementSelector..).is(':hidden') returns boolean.

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.