125
rated 0 times
[
126]
[
1]
/ answers: 1 / hits: 16214
/ 14 Years ago, fri, september 24, 2010, 12:00:00
I have javascript variable obj which represents an element in the DOM and I wish to change its ID. I have attempted to do this by the following, which also illustrates that it does not work!
obj.id = newID;
alert(obj.id); // this gives me newID as required
var element = document.getElementById(newID);
if (element != null) { alert(Hooray); // this alert never gets displayed! }
What is wrong with my code above that means that the id seems to be changed but not picked up in the DOM? Many thanks in advance.
More From » dom