views:

57

answers:

2

Given the following snippet:

<div id="myDiv">
  This is my text <span>with a span</span>
</div>    

JQuery can get the interior string with:

$('#myDiv').text();

Is there a more intuitive way in Prototype than:

$('myDiv').pluck('innerHTML').first().stripTags();
+1  A: 

Hum, doesn't

$('myDiv').innerHTML.stripTags();

work ?

Edit: if you really want a text() method in Prototype, you can do so :

Class.extend(Element, {
  text: function(element) {
    return element.innerHTML.stripTags();
  }
};

and then use it like this :

var txt = $('myDiv').text();
Fabien Ménager
It's not that it doesn't work, it's just that this seems so common a call, I expected a more streamlined way to get the information.
Eric F. Alsheimer
Well, the line with pluck is way more complicated than what I wrote.
Fabien Ménager
A: 

No, I completely agree with you about pluck, that's why I asked the question.

But I like your extend idea. Thanks for your help!

Eric