Hi, > I get the number 4711 in IE with $("test").innerText and in FF with $ > ("test").textContent - does Prototype provide a browser-independent > abstraction for this?
Hopefully you get the *string* "4711" rather than the number 4711 (unless you parse it). :-) `innerHTML` works on all major browsers. It was introduced by IE back in v5 or so, supported by every major browser, and is now standardized in the HTML5 stuff. Of course, it returns the HTML rather than the text, so given: <span id="test"><em>4711</em></span> $('test').innerHTML will return "<em>4711</em>". If you want just the text with the tags stripped away, Prototype adds `stripTags`[1] to the `String` prototype, so $('test').innerHTML.stripTags() will return "4711". If you wanted to shorten that a bit, you could add a `text` function via Element.addMethods[2]: Element.addMethods({ text: function(element) { if (!(element = $(element))) return; return element.innerHTML.stripTags(); } }); (That's off-the-cuff, but I think it's correct; more on the addMethods page.) [1] http://api.prototypejs.org/language/string/prototype/striptags/ [2] http://api.prototypejs.org/dom/element/addmethods/ HTH, -- T.J. Crowder Independent Software Consultant tj / crowder software / com www.crowdersoftware.com On Apr 12, 2:05 pm, Rüdiger Plantiko <ruediger.plant...@astrotexte.ch> wrote: > Hi there, > > is there a cross-browser function for retrieving the text content of > an element? > > If I have an element like > > <span id="test">4711</span> > > I get the number 4711 in IE with $("test").innerText and in FF with $ > ("test").textContent - does Prototype provide a browser-independent > abstraction for this? > > Regards, > Rüdiger -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.