0

How to check if a <span> is hidden or not on webkit browsers (chrome/safari).

Following this code:

<span>
    <div>TEST</div>
</span>

On chrome/safari, this span always appears to be hidden which is not.

Trying both :hidden and :not(:visible) {jq} or (element.offsetWidth === 0 && element.offsetHeight === 0) {js} give same result.

Only setting some kind of css padding to the span seems to get rid of this behaviour, but it's not acceptable in the special case i'm working on.

I'm aware there are some relative tickets on jquery tracker but i cannot figure an adequate workaround.

Could you help me on this one?

SEE DEMO

A. Wolff
  • 74,033
  • 9
  • 94
  • 155

2 Answers2

2

If you set display:block on the span, it seems to work.

http://jsfiddle.net/eREQJ/1/

gotohales
  • 3,665
  • 1
  • 20
  • 34
0
var element = document.getElementById('myspan');
if(element.getAttribute('visibility') == 'hidden'){
    console.log('true')
}else{
    console.log('false')
}

demo

Ryan
  • 5,644
  • 3
  • 38
  • 66