Evik James
Evik James

Reputation: 10483

How can I change the ID of an element and then refer to it by its new id?

I am using jQuery 1.7.1

I am trying to make it so that when one element is keyed in, another element with a specific class will have its id and value changed.

Here is my HTML:

<html><body><table><tr><td>

<input type='text' id="A">
<input type='text' id="B" class='SponsorID'>

</td></tr></table></body></html>

Here is my jQuery:

$("#A").keyup(function() {
   var ThisValue = $("#A").val();
   $(".SponsorID").val(ThisValue);
   $(".SponsorID").attr("id", ThisValue);
});

What works? The value of the element with the class of SponsorID changes.

What doesn't work? The id of the element with the class of SponsorID does NOT change.

I would expect that the id would change. Why does the ID not change?

Here's my fiddle:

http://jsfiddle.net/GWzpU/16/

Upvotes: 0

Views: 55

Answers (1)

Kevin B
Kevin B

Reputation: 95027

It is working as is. Try using google chrome or firebug to inspect the dom.

http://jsfiddle.net/Tentonaxe/GWzpU/17/

Upvotes: 1

Related Questions