You don't need the i or o arguments for the code I posted.  They were
remnants from copying your original code.

>From the docs (http://api.jquery.com/each/):

.each( function(index, Element) )

so the first argument is the index.  .each() is looping over an array
(the array of selected DOM elements), so for each iteration, 'i' (or
whatever argument you declare) would be the position in the array of
the current element.

The second argument is the element itself, which can optionally be
passed in.  Not sure why I couldn't get it to work using "o" rather
than creating a new instance of $( this ) for each iteration... I'd
imagine passing the element in would be more performant, but probably
not enough of a difference to be noticeable.

On Sun, Dec 12, 2010 at 10:32 AM, Rick Faircloth
<ric...@whitestonemedia.com> wrote:
>
> Thanks, Charlie!  That gives me the correct output.
> Now I can move on to the AJAX, JSON, and CF CFC processing
> of data.
>
> Would you be so kind as to actually explain what function
> the "i" and "o" play in "function(i,o)" ?  They're variables/values
> passed into the function, right?
>
> I tested their necessity by taking them out of your
> code and just using function() instead of function(i,o)
> and the code still ran the same.  And even some of the
> example code I found performing this kind of functionality for lists
> used both i and o in the (), but only referenced the "o"
> in the actual function.
>
> I've always been confused about the role these variables
> playing in function(i,o) and whatever was in the ().
> Does the first argument (in this case, "i") always mean something
> specific because it's in the first argument position?  And the
> same with the variable that's in the second position?
>
> I scoured the Internet trying to get a good explanation of using
> these arguments, but haven't found what I needed to understand.
>
> Thanks for any insight you'd share!
>
> Rick
>
>
> -----Original Message-----
> From: Charlie Griefer [mailto:charlie.grie...@gmail.com]
> Sent: Saturday, December 11, 2010 10:51 PM
> To: cf-talk
> Subject: Re: (ot) jQuery question
>
>
> You're missing a # in your selector for #myTable.
> Even with the #, couldn't get your code to run... but the following
> seems to work:
>
> $( document ).ready( function() {
>        var staffOrder = "";
>
>        $( '#myTable tr' ).each( function( i,o ) {
>                if ( staffOrder.length ) {
>                        staffOrder += "," + $( this ).attr( 'class' );
>                } else {
>                        staffOrder = $( this ).attr( 'class' );
>                }
>        });
>
>        alert('staffOrder = ' + staffOrder);
> });
>
> On Sat, Dec 11, 2010 at 8:36 PM, Rick Faircloth
> <r...@whitestonemedia.com> wrote:
>>
>> Hope some of you jQuery and CF users can answer what
>> seems to me should be an easy question, but I can't
>> figure out how to write this jQuery to product a list
>> of values.  (I'll use AJAX and JSON to send the value list
>> to a cffunction for processing).
>>
>> Given this HTML:
>>
>>        <table id="myTable">
>>
>>                <tr class="1">
>>                        <td>1</td>
>>                </tr>
>>
>>                <tr class="2">
>>                        <td>2</td>
>>                </tr>
>>
>>                <tr class="3">
>>                        <td>3</td>
>>                </tr>
>>
>>                <tr class="4">
>>                        <td>4</td>
>>                </tr>
>>
>>                <tr class="5">
>>                        <td>5</td>
>>                </tr>
>>
>>        </table>
>>
>> How can I modify this jQuery to produce
>> a list of the classes of the tr's above?
>>
>> (Output I'm looking for is "1,2,3,4,5" .)
>>
>> I get "staffOrder = " in the alert.  It's as if
>> the "each" function below isn't working at all.
>>
>> Suggestions?
>>
>> Thanks!
>>
>> Rick
>>
>>
>>        $(document).ready(function() {
>>
>>                var staffOrder = '';
>>
>>                $('myTable tr').each(function(i,o) {
>>
>>                        if      (       staffOrder.length
>> )
>>                                {       staffOrder += ',' + o.class;
>> }
>>                        else    {       staffOrder = o.class
>> }
>>
>>                });
>>
>>                alert('staffOrder = ' + staffOrder);
>>
>>        });
>>
>>
>>
>>
>>
>>
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:340020
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to