Wednesday, 16 October 2013

jQuery check if element is visible or hidden

Or you may check if element is visible or hidden with jQuery. Hide or show it according to its visibility.

Test code:

html:

<divclass="wrap-js-action"><spanclass="click js-action">click to show or hide (display:block|none;)</span></div><divclass="target">target</div><divclass="wrap-js-action"><spanclass="click-toggle js-action">click to show or hide by toggle (display:block|none;)</span></div><divclass="target-toggle">target-toggle</div><divclass="wrap-js-action"><spanclass="click-visibility js-action">click to show or hide (visibility:hidden|visible)</span></div><divclass="target-visibility">target visibility</div><divclass="wrap-js-action"><spanclass="click-opacity js-action">click to show or hide (opacity:0|1)</span></div><divclass="target-opacity">target opacity</div><div>last line</div>