This is my text with a span

What is the jQuery $ (element) .text () prototype equivalent?

Given the following snippet:

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

JQuery can get the inner string using:

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

Prototype has a more intuitive way than:

 $('myDiv').pluck('innerHTML').first().stripTags(); 
+7
javascript jquery prototypejs text innerhtml
source share
1 answer

Hum not

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

work?

Edit: if you really want to use the text() method in Prototype, you can do this:

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

and then use it like this:

 var txt = $('myDiv').text(); 
+4
source share

All Articles