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



Question:

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();  


Solution:1

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();  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »