jQuery: The Write Less, Do More JavaScript Library

 « Return to Thread: "Swapping" attributes with attr

Re: "Swapping" attributes with attr

by Charlie Tomlinson :: Rate this Message:

Reply to Author | View in Thread

assuming $(trigger) is a valid selector, this should work:

var theValue = $(trigger).find('input').val();
$(trigger).find('input').attr('id',theValue');



Sceneshift 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?
  

 « Return to Thread: "Swapping" attributes with attr