开发者

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

开发者 https://www.devze.com 2023-01-08 20:11 出处:网络
Given the following snippet: <div id=\"myDiv\"> This is my text <span>with a span</span>

Given the following snippet:

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

JQuery can get the interior string with:

$('#my开发者_StackOverflowDiv').text();

Is there a more intuitive way in Prototype than:

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


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

精彩评论

暂无评论...
验证码 换一张
取 消