On Oct 23, 5:15 pm, Ngan Pham <nganp...@gmail.com> wrote: > Hey guys, > Unless I'm mistaken, there seems to be cross browser incompatibility issue > with innerText and textContent. innerText is IE (and everyone else I > believe), and textContent is Firefox (only, i believe). In anycase, > wouldn't it make sense for Prototype to smooth this out? > > Element.getText() perhaps?
That's actually one big can of worms. Here's a full explanation, if you're interested — http://stackoverflow.com/questions/1359469/innertext-works-in-ie-but-not-in-firefox/1359822#1359822 Most robust solution is actually not `textContent` and not `innerText`, but recursive iteration of children (text) nodes. However that could be "slow", depending on a context where it is to be used. It is, of course, possible to feature test all known discrepancies and craft fast, yet compliant implementation, but the size of such solution would be rather humongous (see, for example, one of my (incomplete) attempts — http://groups.google.com/group/comp.lang.javascript/msg/d1574256dea74077). As always, it's all about context. If you care about consistent results, go for recursive iteration or innerHTML + regex tag stripping (remember that regex would still be fragile). If, on the other hand, it's all about speed — use textContent/innerText and take care of discrepancies as needed. -- kangax --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---