Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Prototype equivalent of JQuery's $(element).text()?

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();
like image 214
Eric F. Alsheimer Avatar asked Jul 21 '10 19:07

Eric F. Alsheimer


1 Answers

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();
like image 51
Fabien Ménager Avatar answered Oct 05 '22 07:10

Fabien Ménager