kangax said:
dhtml wrote:
[...]
There are bugs with Safari 2 and hidden elements (including
visibility:
hidden and display: none). If this presents a problem, there are other
ways around it.
For example, the element that needed to be hidden could be positioned
outside the viewport, instead of using visibility: hidden. Another
That would confuse screen readers, which skip `display:none` content but
announce the one that's merely positioned outside of the viewport.
I see. So the alternatives are:
visibility: hidden
- problem: innerText is "" in Safari 2
position away from view
- problem: a screen reader will read it
Yes, and not only on element but on all of its ancestors as well (for
obvious reasons). Now that you mentioned `visibility:hidden` (which, as
I just tested, does indeed prevent proper `innerText`) we would also
need to take care of that while traversing ancestors. Each of the
ancestor's `visibility` style values should be saved and then restored -
just like with `display` style values.
I really don't like how complex this solution becomes.
I don't either.
I would address the problem if and when it arises. It could be
special-cased to first show the div, then grab its innerText.
I understand that if the constraint involved potentially unknown
ancestors that this would pose a problem.
A saved reference to the property is faster.
var dom = {};
dom.textContent = "textContent" in document.documentElement ?
"textContent" : "innerText";
alert( el[dom.textContent] );
Interesting. I would expect the opposite - after all `dom.textContent`
needs to be resolved to a string before property lookup occurs
(in `el[dom.textContent]`)
Calling a function would be slower than finding dom.textContent.
A string literal "textContent" would be faster, but would fail in IE.
In scope, a local reference could be saved:-
(function(){
var dom = Lib.dom,
textContent = dom.textContent;
//...
})();
If the script is minified, and the local var |textContent| is used many
times, the renaming of textContent to a one-letter identifier would also
have the effect of making the script a bit smaller.