I usually add a method to the Element to do this:-

Element.addMethods({ getText: function(element){
      element = $(element);
      return element.textContent || element.innerText ||
_readTextNodes(element);
      function _readTextNodes(e){
           if(e.nodeType == 3 || e.nodeType == 4){
                 return e.nodeValue;
           }
           var text = '', child = e.firstChild;
           while(child){
                text += _readTextNodes(child);
                child = child.nextSibling;
           }
           return text;
       }
    }
});

$('foo').getText()

On May 10, 5:40 am, vtsuper <vtsu...@gmail.com> wrote:
> Dear sir,
>
> the following is the offical example of read attribute. But would you
> tell me how to make it return the text 'Prototype'?
>
> <a id="tag" href="/tags/prototype" rel="tag" title="view related
> bookmarks." my_widget="some info.">Prototype</a>
>
> $('tag').readAttribute('href');
> // -> '/tags/prototype'
> $('tag').readAttribute('title');
> // -> 'view related bookmarks.'
> $('tag').readAttribute('my_widget');
> // -> 'some info.'
>
> I have try
>
> $('tag').readAttribute('text');
> // -> 'null'
> $('tag').readAttribute(innerHTML);
> // -> 'null'
>
> but both of them not work.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Prototype & script.aculo.us" group.
> To post to this group, send email to prototype-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to 
> prototype-scriptaculous+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to