attr() accepts a function as the second argument:

$(trigger).find('input').val(img_id).attr('name', function(){ return
this.id });

On Jul 2, 11:45 am, Sceneshift <j...@sceneshift.com> wrote:
> Hi, I am trying to swap two attributes around, I am trying to achieve
> something like this:
>
> $(trigger).find('input').attr({value: img_id, name: $(this).attr('id')});
>
> As you can see, I am trying to swap the value of the name attribute with the
> value of the id attribute. The above code does not work, as $(this) is not
> input field object.
>
> Can anyone suggest a clean way in which I can do the above?
> --
> View this message in 
> context:http://www.nabble.com/%22Swapping%22-attributes-with-attr-tp24308061s...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to