New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 96839 link

Starred by 6 users

Issue metadata

Status: WontFix
Owner:
(inactive)
Closed: Apr 2015
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

Element.innerText returns blank string when element has visibility: hidden set by CSS Stylesheet

Reported by gtg1...@gmail.com, Sep 16 2011

Issue description

Chrome Version       : 13.0.782.220
OS Version: 5.1 (Windows XP)
URLs (if applicable) :
Other browsers tested:
Add OK or FAIL after other browsers where you have tested this issue:
Safari 5:
Firefox 4.x:
IE 7/8/9:

What steps will reproduce the problem?
1. http://jsfiddle.net/XBdQq/
2. Access an element's innerText when it has visibility: hidden set by a CSS stylesheet
3. it will be "" rather than its actual content

What is the expected result?
http://jsfiddle.net/BUeZj/1/
Element.textContent works fine
This leads to several bugs in some frameworks also.

What happens instead?


Please provide any additional information below. Attach a screenshot if
possible.

UserAgentString: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1



 

Comment 1 by gtg1...@gmail.com, Sep 16 2011

The second JS fiddle shows correct behavior when visibility: visible;
http://jsfiddle.net/XBdQq/1/ shows using visibility: hidden along with textContent and how that functions as expected.

Comment 2 by Deleted ...@, Sep 30 2011

I've tried to print the innerText/textContent of a visibility:hidden div, here is the result. OK means can get the string, empty means only get empty string.

Safari 5: innerText: empty; textContent: OK.
Firefox 7: innerText: not support; textContent: OK.
IE 7/8: innerText: OK. textContent: not support.
IE 9: innerText: OK. textContent: OK.
opera 11: innerText: OK. textContent: OK.
Project Member

Comment 3 by bugdroid1@chromium.org, Mar 10 2013

Labels: -Area-Undefined

Comment 4 by samli@chromium.org, Apr 15 2015

Owner: samli@chromium.org
Status: WontFix
This appears to be expected behaviour. Matches firefox.
Please use textContent instead.

Comment 5 by kan...@gmail.com, Apr 15 2015

How could it match Firefox if Firefox doesn't support `innerText` in the first place? :)

IE and WebKit/Blink are the ones diverging on "visibility: hidden" behavior — http://perfectionkills.com/the-poor-misunderstood-innerText/#diff-with-textContent

Considering that WebKit/Blink don't include "opacity: 0" elements, this is somehwat of a consistency issue. IE, on the other hand, only excludes "display: none" — which makes sense, since those are not part of the flow (unlike "visibility: hidden", "opacity: 0", "text-indent: -9999px", "color: transparent", and myriad of other ways one could come up with)

So I'd argue that WebKit/Blink behavior is the odd one. Whether that could be "fixed" is a different matter; there might be sites relying on this. And technically there's nothing to "fix" in the first place, since `innerText` has never been standardized.

Still, if this doesn't break anything, I think WebKit/Blink should follow IE lead in this particular aspect of problematic beast that innerText is :)

Sign in to add a comment