Issue with changing an attribute with jquery

Posted by rshivers on Stack Overflow See other posts from Stack Overflow or by rshivers
Published on 2010-05-20T13:39:19Z Indexed on 2010/05/20 13:40 UTC
Read the original article Hit count: 161

Filed under:

Hello, I'm having an issue with changing the attribute for an id and can't seem to figure out what I'm doing wrong. I guess it doesn't help that I'm new to this also.

I have a function that tests to make sure that I am pulling the correct id from the row in my form that I have dynamically created. It goes something like this:

myFunction() {
  var id = $(id).attr("id");
  alert("This is my id " + id);
}

This works with no problem and when I click the button assigned to alert me of my id it will give give me the id of the dynamic row in my form. The issue is now when I try to change the id with this:

changeId() {
  var newId = $(id).attr("id", "x");
  alert("This is my new id " + newId);
}

What happens in this case is that it will alert saying "This is my new id [object Object]" instead of giving me the new id. Any suggestions? I'd really appreciate any help with this.

© Stack Overflow or respective owner

Related posts about jQuery