Hi,

JLopez wrote:
>> I'm trying to get the text from the first <TD> of every <TR> in the
>> <TBODY> of my table.
>> To make it trickier I also would lke unique items.
>> 
>> This is what I have so far that works, but I feel like there should be
>> a cleaner way of doing it.
>> 
>> My table id is 'search'
>> I want to dump the contents into a div named 'distinct'

T.J. Crowder wrote:
> Hi,
> 
> I'd think CSS3 "nth-child" selectors[1] should be able to help (not
> with the unique bit).  Something like this:
> 
>     list = $('search').down('tbody').select('tr > td:nth-child(1)');
>     list.each(function(td) {
>         // ...do something with the td here... */
>     });
> 

I think this is a great example for Enumerable [1] usage.
Try the code below. I have no time to test it properly at the moment, 
but it should work. If not, read about Enumerable and you should be 
able to correct me.

     var list =
         $('search').down('tbody').select('tr > td:nth-child(1)');

     list.map( function(td) {
        //lets map each td to its concent
         return tr.down('a').innerHTML;
     }).uniq().findAll(function(content) {
        //test if there was 'a' element and if it contains what it
         //should. I assume the sk is defined.
        return (content && content.toLowerCase().include(
             sk.toLowerCase()));
     }).each(function (content) {
         $('distinct').insert(content);
     });


[1] http://prototypejs.org/api/enumerable


Hope this helps.

-- 
Regards,
SWilk


--~--~---------~--~----~------------~-------~--~----~
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