Showing posts with label hidden. Show all posts
Showing posts with label hidden. Show all posts

Thursday, December 12, 2013

Checking if an element is hidden with jQuery

Html

<form style='display: none'>
<input id='name' type='text' style='display: inline-block' />
</form>

jQuery code


if( $("input#name").is(":visible") ) {
    /* do something, selector is not hidden */
}

This will select the input field and then test correctly whether it is visible in the DOM. This check will make sure all parent elements are visible too, as well as the original CSS display attribute.