views:

22

answers:

2

how do we check whether a input box is visible or not....then store its state into variable to be outpu via alert ?

right now i'm using and i think it wrong. can any body help ?

<input type="hello" name="hello" value="" style="visibility:hidden"/>

function testhideinput(){
            var $input_state = $('input:text[name=hello]').is('visibility');
alert($input_state);
}
A: 
var inputState = $('input:text[name=hello]').css('visibility');

if(inputState == "hidden") {
    // do stuff
}
else {
    // do some other stuff
}
Marko
A: 

Try it like this.

var $input_state = $('input:text[name=hello]').is(':visible');

That's how it works in my code for a div.

Jayesh
`:visible` won't work. From the documentation: "Elements with `visibility: hidden` or `opacity: 0` are considered to be visible"
Yi Jiang
In that case, it would be a good idea to use `.hide()` instead of setting css property `visibility:hidden` manually.
Jayesh