I have some basic css:
#awesome1{
color: red;
}
and html:
<div id="awesome1"></div>
I want to change the id awesome1
to awesome2
with jQuery, but keep the css from old id.
But when I type:
jQuery('#awesome1').attr('id', 'awesome2');
It changes the div
's id in DOM, but of course, my div
loses the color: red
.
Is there a way to change the "id in css" or "copy all the attributes" (I cannot assume that's only color
) from old id to new one?
Update, clarification:
The point is, I change the id to another dynamically, based on some ajax data - I don't know (at the time I generate the css), which id it will be, so I cannot assume that it will be awesome2
and hard-code it in e.g. css.
P.s. Please read especially the bold text before posting new answers. I'm aware of methods when I could assume what would be the new id and hard-code it to css, or resign from id for classes. But in my example, I cannot. And my problem is like the topic: Change id but keep the css related to the old id in jQuery.