Like so:
$('input').each(function(i){
$(this).attr('name', i);
});
Nice and simple!
--John
On 8/23/07, goodieboy <[EMAIL PROTECTED]> wrote:
>
> OK, I thought I knew jQuery pretty well. But this is completely
> stumping me. What I want to do is iterate through a newly attached set
> of input elements, and set their names based on a dynamic
> (incrementing) number. But the only value that ever gets used is the
> initial value of the variable. I've tried everything, attaching the
> value to the dom object, and then in the loop trying to access it
> (still the same original value), using a global variable, a function
> to get the value, all return the original value that I set the
> variable to.
>
> What am I doing wrong? Here is an example:
>
> for(i=0; i<10; i++){
> $('input').each(function(){
> $(this).attr('name', i);
> });
> }
>
> Here, all of the inputs get the value 9. How can I make then all get
> the current incremented value of i?
>
> Thank you for any tips!
> Matt
>
>