Thanks for the all of the suggestions. Any chance something like this can be
added into Prototype for cross-browser compatibility and ease of use?
-Hector

On Wed, Oct 8, 2008 at 10:57 AM, solidhex <[EMAIL PROTECTED]> wrote:

>
> You can also use Prototype's methods for removing white space,
> something like:
>
>                $('foo', 'bar', 'baz').each(function(el) {
>
>  console.log(el.cleanWhitespace().childNodes[1].nodeValue.strip());
>                });
>
> That seems to return what you're after.
>
> On Oct 8, 8:53 am, Walter Lee Davis <[EMAIL PROTECTED]> wrote:
> > Getting the text is pretty simple:
> >
> >         $$('li').each(function(elm){
> >                 alert (elm.innerHTML.gsub(/<[^>]+>/,''))
> >         });
> >
> > The issue lies with the LI that has a UL in it. In that case, you get
> > "Bar [bunch of whitespace] Baz", then next you get just "Baz". If the
> > order of elements is important, then you will need to use either a
> > smarter selector or a test inside the loop to only return the non-
> > child portion of the element.
> >
> > Walter
> >
> > On Oct 8, 2008, at 11:31 AM, Hector Virgen wrote:
> >
> > > Maybe there's a better way to approach my problem.
> >
> > > I have a nested unordered list that contains an image (icon) and
> > > some text in each LI. I want to extract just the text part of the
> > > LI without the image.
> >
> > > <ul>
> > >     <li id="foo"><img src="icon.png" alt="" />Foo</li>
> > >     <li id="bar"><img src="icon.png" alt="" />Bar
> > >         <ul>
> > >             <li id="baz"><img src="icon.png" alt="" />Baz</li>
> > >         </ul>
> > >     </li>
> > > </ul>
> >
> > > What I want is extract 'Foo', 'Bar', and 'Baz' from each of the
> > > LIs. Any ideas on how to go about this, or should I restructure my
> > > html?
> >
> > > -Hector
> >
> > > On Wed, Oct 8, 2008 at 3:48 AM, Søren Erland Vestø
> > > <[EMAIL PROTECTED]> wrote:
> > > This might not work in IE, as IE doesn't return textnodes in
> > > childNodes.
> >
> > > /Søren
> >
> > > On 07/10/2008, at 21.24, Hector Virgen wrote:
> >
> > >> Thanks! That should do the trick :)
> >
> > >> On Tue, Oct 7, 2008 at 12:12 PM, Justin Perkins
> > >> <[EMAIL PROTECTED]> wrote:
> >
> > >> I think you will need to use the native methods to get the text nodes
> > >> as Prototype filters them out. This will work though:
> >
> > >> $A( $('some-element-id').childNodes ).select( function(element){
> > >> return element.nodeType == 3; } )
> >
> > >> Or better yet:
> >
> > >> Element.addMethods({
> > >>  textNodes: function(element){
> > >>    return $A(element.childNodes).select( function(child){ return
> > >> child.nodeType == 3; } );
> > >>  }
> > >> });
> >
> > >> Then you can just do: $('some-element-id').textNodes();
> >
> > >> -justin
> >
>

--~--~---------~--~----~------------~-------~--~----~
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-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to